【问题标题】:Android -Compress bitmap array of imagesAndroid - 压缩图像的位图数组
【发布时间】:2015-02-05 04:17:33
【问题描述】:

我有一个Bitmap [] images。但是行

images.compress(Bitmap.CompressFormat.PNG, 100, bos);

导致错误

无法调用 compress(Bitmap.CompressFormat, int, ByteArrayOutputStream) 上的数组类型 Bitmap[]

在我的搜索中,我得到了压缩为一个位图的代码。但没有压缩位图数组。

代码

Bitmap[] images = {BitmapFactory.decodeResource(getResources(),R.drawable.candle1),BitmapFactory.decodeResource(getResources   
(),R.drawable.candl3),BitmapFactory.decodeResource(getResources(),R.drawable.senson),BitmapFactory.decodeResource(getResources(),R.drawable.lawn)}; 
ByteArrayOutputStream bos=new ByteArrayOutputStream();
 //  images.compress(Bitmap.CompressFormat.PNG, 100, bos);
img=bos.toByteArray();

【问题讨论】:

  • 您希望从压缩位图数组中得到什么?

标签: android arrays bitmap


【解决方案1】:

您应该循环压缩 Bitmap 数组,如下所示:

byte[][] img = new byte[images.length][];

for (int i = 0; i < images.length; i++) {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    images[i].compress(Bitmap.CompressFormat.PNG, 100, bos);

    // use a 2D array for img if you want to retain the byte arrays for all the bitmaps
    img[i] = bos.toByteArray();
}

我希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-03
    • 2013-11-15
    • 1970-01-01
    相关资源
    最近更新 更多