毕加索加载字节数组

问题描述 投票:5回答:1

我需要将位图(在文件系统中)加载到字节数组中以上传它,但需要:

  • 调整为500x500并以字节为单位[]。
  • 异步

我可以滑行来做

Glide.with(context)
    .load(“/user/profile/photo/path”)
    .asBitmap()
    .toBytes()
    .centerCrop()
    .into(new SimpleTarget<byte[]>(250, 250) {
        @Override
        public void onResourceReady(byte[] data, GlideAnimation anim) {
            // Post your bytes to a background thread and upload them here.
        }
    });

但我不想仅仅为此而包括它。用毕加索做的任何方式?

android file-upload picasso
1个回答
0
投票

试试这个解决方案

Bitmap bmp = intent.getExtras().get("data"); 
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream); 
byte[] byteArray = stream.toByteArray();
© www.soinside.com 2019 - 2024. All rights reserved.