过滤图像android?
我用这个算法来过滤andriod中的图像 但是这些图像并不像预期的那样,我可以找到其他方法来实现这一点。你看,应用程序已经做到了这一点,使它变得很快,这个算法太慢了过滤图像android?,android,image,filter,convolution,Android,Image,Filter,Convolution,我用这个算法来过滤andriod中的图像 但是这些图像并不像预期的那样,我可以找到其他方法来实现这一点。你看,应用程序已经做到了这一点,使它变得很快,这个算法太慢了 关于我使用这个公式根据图像的扩展来过滤图像 class FileExtensionFilter implements FilenameFilter { public boolean accept(File dir, String name) { return (name.endsWith("
关于我使用这个公式根据图像的扩展来过滤图像
class FileExtensionFilter implements FilenameFilter {
public boolean accept(File dir, String name) {
return (name.endsWith(".png") || name.endsWith(".PNG"));
}
如果你是从sd卡上取的,请告诉我。我有它的代码。我最近在那里发布了一个你尝试过的代码的更快版本,你应该试一试 顺便问一下,你说的句子意象不符合预期是什么意思?也许你只是使用了一个错误的矩阵;你可以找到一些矩阵的例子 这是你要的样品。如果不需要缩放/偏移像素颜色,则应添加不同的
卷积实现,而不需要这些参数和相关的不必要计算
class Convolution {
private static Bitmap convolute(Bitmap bmp, Matrix mat, float factor, int offset) {
/* ... */
}
private static Matrix getEdgeEnhanceMatrix() {
Matrix m = new Matrix();
m.setValues(new float[] {
0, 0, 0,
-1, 1, 0,
0, 0, 0
});
return m;
}
// the simple way
public static Bitmap edgeEnhance1(Bitmap bmp) {
return convolute(bmp, getEdgeEnhanceMatrix(), 1f, 0);
}
// if you want to apply filter to border pixels
// warning: really memory consuming
public static Bitmap edgeEnhance2(Bitmap bmp, int bgColor) {
// create a bigger canvas
Bitmap bigger = Bitmap.createBitmap(bmp.getWidth() + 2, bmp.getHeight() + 2, bmp.getConfig());
Canvas cBigger = new Canvas(bigger);
// paint background
cBigger.drawColor(bgColor);
// draw the bmp you want to manipulate from (1,1)
cBigger.drawBitmap(bmp, 1, 1, null);
// compute convolution
bigger = convolute(bigger, getEdgeEnhanceMatrix(), 1f, 0);
// create the result and project the convolution at (-1,-1)
Bitmap rt = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), bmp.getConfig());
Canvas cRt = new Canvas(rt);
cRt.drawBitmap(bigger, -1, -1, null);
return rt;
}
}
感谢您的回复,当我应用阵列时,会在几像素之外显示图像。我会试试你的代码。你注意到的像素置换是因为,要转换一个像素,你需要它周围的八个像素:所以你会在图像周围“松开”一个像素宽的矩形-或者在任何情况下,如果你像我这样克隆原始像素,这些像素将不会被转换。那么你会创建矩阵吗?float src[]={0,0,0,-1,0,0,0};矩阵mx=新矩阵();mx.setValues(src);图16.155。浮雕m.setValues(新的float[]{-2,-1,0,-1,1,1,0,1,2});白色像素,我该如何解决这个问题?问题涉及到图形过滤,而不是按文件扩展名过滤。