Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Picasso to load byte array

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?

like image 613
Daniel Gomez Rico Avatar asked Nov 22 '22 15:11

Daniel Gomez Rico


1 Answers

Try this solution

Bitmap bmp = intent.getExtras().get("data"); 
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream); 
byte[] byteArray = stream.toByteArray();
like image 56
Muthukrishnan Suresh Avatar answered Dec 17 '22 15:12

Muthukrishnan Suresh