java 图片字节_如何从java字节数组中解码图片

我从服务器获取一个字节数组,然后将其转换为imageView。问题是,当我使用tomkat maven插件时,一切都很好,但当我开始使用tomkat版本8时,发现

BitmapFactory.decodeByteArray

我试过了78 9

// IMAGE MESSAGE

//Android client

if (message.getImageMessage() != null) {

MessageViewHolder2 holder = new MessageViewHolder2();

LayoutInflater messageInflater = (LayoutInflater)

context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

byte [] ar = message.getImageMessage().getByteArray();

Bitmap bmp = BitmapFactory.decodeByteArray(ar , 0, ar.length);

if (bmp!=null) {

ByteArrayOutputStream out = new ByteArrayOutputStream();

bmp.compress(Bitmap.CompressFormat.JPEG, 10, out);

byte[] byteArray = out.toByteArray();

// MY IMAGE

if (message.getImageMessage().isFromMe()) {

// Convert bytes data into a Bitmap

convertView =

messageInflater.inflate(R.layout.image_my_message_layout, null);

holder.messageBody = (ImageView)

convertView.findViewById(R.id.imageMessageView);

holder.messageBody.setImageBitmap(bmp);

//ÐÑÑиÑлÑем ÑиÑÐ¸Ð½Ñ Ð¸ вÑÑоÑÑ Ð¸Ð·Ð¾Ð±ÑажениÑ

double width = bmp.getWidth();

double height = bmp.getHeight();

double koef = height / 1000;

int newWidht = (int) (width / koef);

int newheight = (int) (height / koef);

Bitmap bmHalf = Bitmap.createScaledBitmap(bmp, newWidht, newheight, false);

holder.messageBody.setImageBitmap(bmHalf);

}

}

// Getting pictures on the server

public int size =1_000_000;

int sizeFoto = 0;

public ByteBuffer bbuf = ByteBuffer.allocate(size);

@OnMessage

public void processUpload(ByteBuffer msg, boolean last, Session session) {

sizeFoto +=msg.array().length;

if(msg.remaining()!=1) {

bbuf.put(msg);

}

else{

System.err.println("Size : "+sizeFoto);

bbuf.put(msg);

sendBuf(bbuf);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值