¿如何处理字节数组中的图像?

时间:2018-07-08 03:53:57

标签: java android bitmap

我尝试过此方法,但是当我显示位图时我什么都看不到,我想要在原始图像上绘制白色轮廓

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.dog);

 public byte[] myImagetoBytes(Bitmap bitmap){
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
        return stream.toByteArray();
    }



 byte[] bytes = myImagetoBytes();

 bytes[0] = 1 & 0xff;

 Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);

 this.imageView.setImageBitmap(bitmap);

1 个答案:

答案 0 :(得分:0)

不确定代码应该做什么,但是如果要绘制位图,则应使用Canvas。您使用其构造函数创建它:

Canvas canvas = new Canvas(bitmap);

然后您可以像这样使用它:

 Paint paint = new Paint();
 paint.setColor(Color.GRAY);
 RectF ovalRect = new RectF(0, 0, 10, 10);
 canvas.drawOval(ovalRect, paint);