Get Bitmap Attached to Imageview

How to get the whole bitmap attached to an ImageView?

If you just want the Bitmap from a ImageView the following code may work for you:-

Bitmap bm=((BitmapDrawable)imageView.getDrawable()).getBitmap();

I think that's what you wanted.

Get Bitmap attached to ImageView with background

Try to get bitmap using DrawingCache..
try following code:

image.setDrawingCacheEnabled(true);

// this is the important code :)
// Without it the view will have a dimension of 0,0 and the bitmap will be null
image.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
image.layout(0, 0, image.getMeasuredWidth(), image.getMeasuredHeight());

image.buildDrawingCache(true);
Bitmap bitmap = Bitmap.createBitmap(image.getDrawingCache());
image.setDrawingCacheEnabled(false); // clear drawing cache

GetBitmap from ImageView

Try this, hope it helps

ImageView imageView = findViewById(R.id.image);
BitmapDrawable bd = (BitmapDrawable) imageView.getDrawable();
Bitmap b = bd.getBitmap();

Get Bitmap attached to ImageView


Bitmap bitmap = ((BitmapDrawable)image.getDrawable()).getBitmap();

Get bitmap from imageview in viewpager with glide

You can get Bitmap from DrawingCache. After Settting image in ImageView you can get it as below:

    imageViewPreview.setDrawingCacheEnabled(true);
imageViewPreview.buildDrawingCache(true);
final Bitmap bmp = Bitmap.createBitmap(layout.getDrawingCache());
imageViewPreview.setDrawingCacheEnabled(false);

If you need full size image then this is not right way i think .A better solution would be to get it From Glide as Bitmap . If full image was loaded already it will be quick (from cache) if not then it will load the full image from server or you can still use Drawing cache in case of No internet connection and glide failure.

Glide.with(imageView.getContext())
.asBitmap()
.load("imageUrl")
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
// Use resource here
}
});
}

Can't get Bitmap from ImageView as a BitmapDrawable

This should solve your problem:

val bitmap = (mDressImage1?.drawable as? BitmapDrawable)?.bitmap

How to get the current drawable in the ImageView and turn it into a bitmap?

get Bitmap with this method :

BitmapDrawable bitmapDrawable = ((BitmapDrawable) imageView.getDrawable());
Bitmap bitmap = bitmapDrawable .getBitmap();

decodeResource gives you bitmap from resource ,
for example , if you want to read an image from drawable folder you need decodeResource but in this case you can get bitmap from imageview directly



Related Topics



Leave a reply



Submit