我正在开发一个android水印项目,我需要一种方法来为R,G和B生成2D数组,并在从其他人完成的WM方法取回图像后重新创建图像。(有这种方法,所以我无法更改)。
这是我从位图创建R,G,B的方法:
Bitmap image = BitmapFactory.decodeFile("/sdcard/Watermarking/WM_20151208_183746_1282108897-1.jpg");
int height = image.getHeight();
int width = image.getWidth();
short [][] red = new short[height][width];
short [][] green = new short[height][width];
short [][] blue = new short[height][width];
int column = 0;
int row = 0;
while(row < height)
{
while(column < width)
{
int pixel = image.getPixel(column, row);
red[row][column] = (short) Color.red(pixel);
green[row][column] = (short) Color.green(pixel);
blue[row][column] = (short) Color.blue(pixel);
column++;
}
row++;
}
displayImage(red, green, blue);
这是我用来测试自己所做的正确性的方法:
public void displayImage(short [][] red, short [][] green, short [][] blue)
{
short height = (short) red.length;
short width = (short) red[0].length;
Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
int column = 0;
int row = 0;
while(row < height)
{
while(column < width)
{
image.setPixel(column, row, Color.rgb(red[row][column], green[row][column], blue[row][column]));
column++;
}
row++;
}
ImageView imageView = (ImageView) findViewById(R.id.imageView);
imageView.setImageBitmap (image);
}
出现的图像是黑色图像,即使它应该是正确的。任何帮助表示赞赏。
通过简单地调试代码,您无需重复设置列变量即可重复填充数组的第一行
添加:
column = 0;
在两个循环之后(填充和读取数组);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句