Picasso to load byte array

7.7k views Asked by At

I need to load a bitmap, that is in the file system, into byte array to upload it but needs to be:

  • Resized to 500x500 and in bytes[].
  • Async

I can do it with glide

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.
        }
    });

but I dont want to include it just for that. Any way to do it with picasso?

1

There are 1 answers

3
Muthukrishnan Suresh On

Try this solution

Bitmap bmp = intent.getExtras().get("data"); 
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream); 
byte[] byteArray = stream.toByteArray();