我从服务器获取一个字节数组,然后将其转换为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);
}
}