5
当我使用copyPixelsFromBuffer和copyPixelsToBuffer,位图显示不一样的,我曾尝试下面的代码:新点阵图已变更上复制使用缓冲区
Bitmap bm = BitmapFactory.decodeByteArray(a, 0, a.length);
int[] pixels = new int[bm.getWidth() * bm.getHeight()];
bm.getPixels(pixels, 0, bm.getWidth(), 0, 0,bm.getWidth(),bm.getHeight());
ByteBuffer buffer = ByteBuffer.allocate(bm.getRowBytes()*bm.getHeight());
bm.copyPixelsToBuffer(buffer);//I copy the pixels from Bitmap bm to the buffer
ByteBuffer buffer1 = ByteBuffer.wrap(buffer.array());
newbm = Bitmap.createBitmap(160, 160,Config.RGB_565);
newbm.copyPixelsFromBuffer(buffer1);//I read pixels from the Buffer and put the pixels to the Bitmap newbm.
imageview1.setImageBitmap(newbm);
imageview2.setImageBitmap(bm);
为什么位图BM和newbm不显示相同的内容?
BitmapFactory.Options opts = new Options(); opts.inPreferredConfig = Config.RGB_565; \t \t \t \t \t bm = BitmapFactory.decodeByteArray(a,0,a.length,opts); 原始位图的配置是RGB565,即使我没有设置配置,配置默认为RGB565 ... – Hexor 2012-04-01 16:08:47
@Hexor在我的回答工作中描述的其他方法吗? 'newbm'看起来和'bm'有什么不同? – 2012-04-01 18:27:15
尺寸不对,质量很低。我自己找到了一个解决方案,创建一个名为originBm的Bitmap,并调用BitmapFactory的decode方法初始化originBm(只要确保参数可以初始化originBm),然后使用newbm = originBm; newbm.copyPixelsFromBuffer(缓冲器1)。在此之后,新手可以展示正确的东西。我不知道是哪个原因造成这种情况,但我想也许在使用copyPixelsFromBuffer()时,我们会错过createBitmap()方法无法给我们的东西。 – Hexor 2012-04-02 09:06:10