【问题标题】:Android create bitmap from RGB 2D arraysAndroid 从 RGB 2D 数组创建位图
【发布时间】:2016-07-02 19:08:38
【问题描述】:

我正在开发一个 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);
}

出现的图像是黑色图像,尽管它应该是正确的。任何帮助表示赞赏。

【问题讨论】:

    标签: android bitmap rgb pixel


    【解决方案1】:

    通过简单地调试你的代码,你只是通过不重置列变量来重复填充数组的第一行

    添加:

    column = 0;
    

    在两个循环之后(填充和读取数组);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-03
      • 2016-08-19
      • 1970-01-01
      • 1970-01-01
      • 2021-10-21
      • 2023-03-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多