Create Bitmap from drawable - android

I would like to add an image (Bitmap) over another one. For that I am only using Bitmaps (fot the image I draw in and the image I add), but the Bitmap I am using is actually a resource in my drawable resource. So Is there a way to create a Bitmap that contains my drawable ?

Use decodeResource() of BitmapFactory to convert drawable resource into Bitmap as follows...
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.your_drawable);

Try this:
Bitmap bitmap= BitmapFactory.decodeResource(context.getResources(),
R.drawable.icon_name);

Related

High resolution bitmap quality issue

I get bitmap from drawable but bitmap sized is maximum 1024*1024..i will try to get
bitmap full resolution from drawable but ican't get.I will try to all possibile work but not get how to solve this problem.I try to last 4 days but not get any proper solution.I want to need get full resolution bitmap from drawable
BitmapDrawable drawable = (BitmapDrawable) img.getDrawable();
Bitmap bmp = drawable.getBitmap();
Bitmap b = Bitmap.createScaledBitmap(bmp, 1025, 1025, false);
First, you need to put your image file in drawable-nodpi. nodpi will not resize your drawable.
Second, you can use BitmapFactory.decodeResource(getResources(), R.drawable.bg_pop); to retrieve Bitmap from resource.
Edit-
You can use 'inScaled' options when retrieving Bitmap from the resource. I checked from my project. (original image size is 1920x1080
val options= BitmapFactory.Options()
options.inScaled = false
val bitmap = BitmapFactory.decodeResource(resources, R.drawable.splatoon, options)
ScreenShot, in imgur

Loading .svg file from web or local cache in Android

I'm using Glide to load .png image asynchronously.
File file = Glide.with(context).load(location).downloadOnly(1024, 1024).get();
In case of .svg, the file is created but it is not loading into ImageView.
ImageView only accepts Bitmaps or VectorDrawables.
SVG is neither of the two, even if VectorDrawable descends from it.
Get a PictureDrawable from your SVG file. Then you need to create a Bitmap from the size of the PictureDrawable and give it to a Canvas.
PictureDrawable pictureDrawable = svg.createPictureDrawable();
Bitmap bitmap = Bitmap.createBitmap(pictureDrawable.getIntrinsicWidth(), pictureDrawable.getIntrinsicHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawPicture(pictureDrawable.getPicture());
currentBitmap = bitmap;

Maximum Bitmap height and width Supported in Android

I tried to get full size bitmap from drawable but not get.My image store into drawable folder and its sized 1082*1673 and when i get bitmap from drawable its sized 662*1024.
I tried to all possible changes
My code shown below
Bitmap bmp = BitmapFactory.decodeResource(getResources(),
R.drawable.t_0001, o);

How to load a Bitmap in LAB color space?

Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.img);
This line loads an image in RGB. What about a LAB colors?
I found ColorSpace.Model.LAB constant but not how to use it.

Convert BitmapDrawable to Bitmap

In my project a bitmap gets filled with text and another bitmap, the method to add the text to the bitmap returns a BitmapDrawable.
I want to save this BitmapDrawable as a pdf file, so I can email the original bitmap, with text and other image(s) added.
For this, I'll need a regular Bitmap instead of a BitmapDrawable.
I can't seem to find any answers on this, because I don't have a reference to a drawable in a drawable folder, I just have a BitmapDrawable to work with.
Any ideas on this?
BitmapDrawables support a getter for the bitmap.
Bitmap bitmap = bitmapDrawable.getBitmap();

Categories

Resources