简体   繁体   English

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

[英]¿How to manipulate an image from an array of bytes?

I tried this but when I show the bitmap I can not see anything, what I want is to paint a white outline on the original image 我尝试了一下,但是当我显示位图时我什么都看不到,我想要的是在原始图像上绘制白色轮廓

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);

Not sure what your code is supposed to do, but if you want to draw over a bitmap, you should use Canvas . 不确定代码应该做什么,但是如果要绘制位图,则应使用Canvas You create it with its constructor: 您使用其构造函数创建它:

Canvas canvas = new Canvas(bitmap);

And then you can use it like this: 然后您可以像这样使用它:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM