我创建了一个循环遍历两个位图并将像素数据存储到二维数组(compare1[][] & compare2[][])的应用程序。
我相信我的代码在某种程度上是有效的。看起来它保存了位图,但是当我后来去画廊时它不在那里。任何想法将不胜感激;这是我的代码示例:
public void getPixels(int[][] compare2,int[][]compare1, int x)
{
Bitmap difference = Bitmap.createBitmap(width, height, Config.ARGB_8888);
for(int i = 0; i<width-1; i++)
{
for(int j=0; j<height-1; j++)
{
int mColor = BIT.get(x).getPixel(i, j);
int alpha = Color.alpha(mColor);
int red = Color.red(mColor);
int green = Color.green(mColor);
int blue = Color.blue(mColor);
int xAvg = ((red+green+blue)/3);
compare2[i][j] = xAvg;
if ((compare1[i][j] - compare2[i][j]) < 50)
{
difference.setPixel(i, j, -16777216);
//System.out.println("No Significant Change");
}
else
{
difference.setPixel(i, j, -1);
//System.out.println("Change");
}
}
}
try {
String path = Environment.getExternalStorageDirectory().toString();
OutputStream fOut = null;
File file = new File(path,"Test.jpg");
fOut = new FileOutputStream(file);
difference.compress(Bitmap.CompressFormat.JPEG, 80, fOut);
fOut.flush();
fOut.close();
fOut = null;
} catch (Exception e) {
e.printStackTrace();
}
}