Get original size bitmap from drawable - 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
[1] Bitmap icon = BitmapFactory.decodeResource(getResources(),R.drawable.t_0001);
[2] BitmapFactory.Options o = new BitmapFactory.Options();
o.inTargetDensity = DisplayMetrics.DENSITY_DEFAULT;
Bitmap bmp = BitmapFactory.decodeResource(getResources(),
R.drawable.t_0001, o);

Put that image must be in drawable-xxhdpi folder

I guess if you put your images under the Assets folder (or subfolder inside assets), the auto resize will not happen.

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

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 save a bitmap with same dimensions that of original?

I am writing a function, which takes a bitmap, edits it and saves it.
But the problem is that the saved image is not having the same dimensions.
Can anyone help me fix it? I want the output image to be of same length and width as that of the original image.
This is my code -
public void bitTest(View v) throws IOException {
Drawable t=getResources().getDrawable(R.drawable.slider_touch,getTheme());//the image to be processed
Bitmap bit=((BitmapDrawable) t).getBitmap();//its bitmap
Bitmap finalImage=Bitmap.createBitmap(bit.getWidth(),bit.getHeight(),bit.getConfig());//creating another bitmap of same dimensions
Context context=getApplicationContext();
FileOutputStream fos = context.openFileOutput("test.png", Context.MODE_PRIVATE);//saving
finalImage.compress(Bitmap.CompressFormat.PNG,100, fos);
fos.close();
}
Here the original size is having dimensions of 288x192 but the output image has dimensions of 605x403.
Where am i wrong?
Also i have tried changing the quality, but it doesn't works.
When placing the image resources in drawable directory, the decoded image size depends upon the screen size of the running device.
Keep your drawable inside the folder drawable-nodpi rather than other drawable directories so that the image size remains preserved.
Also rather than using BitmapDrawable, you can directly decode a bitmap from resource using BitmapFactory.decodeResource()

Regarding mistake while getting bitmap from the mipmap folder

I have included demo project in my visual studio. But It is showing me error in the following statments. I have copied images and past into the mipmap as well.
Please, can any one check what is the mistake and guide me as well. Thank you in advance.
Bitmap fuelbar= BitmapFactory.decodeResource(getResources(), );//Bitmap image gets the fuel image from the resources folder
Bitmap blastCraft = BitmapFactory.decodeResource(getResources(), R.drawable.explosion);//Bitmap image gets the explosion image from the resources folder
Bitmap thruster = BitmapFactory.decodeResource(getResources(), R.drawable.thruster);//Bitmap image gets the small thruster image from the resources folder
Bitmap main_flame = BitmapFactory.decodeResource(getResources(), R.drawable.main_flame);//Bitmap image gets the main flame image from the resources folder
What folder you placed your bitmaps ? drawable or mipmap or both ?
If you placed in mipmap folder, you should change your code to:
Bitmap blastCraft = BitmapFactory.decodeResource(getResources(), R.mipmap.explosion);//Bitmap image gets the explosion image from the resources folder
Bitmap thruster = BitmapFactory.decodeResource(getResources(), R.mipmap.thruster);//Bitmap image gets the small thruster image from the resources folder
Bitmap main_flame = BitmapFactory.decodeResource(getResources(), R.mipmap.main_flame);//Bitmap image gets the main flame image from the resources folder

Android drawable-nodpi not working?

My 64x64 png image is getting scaled down in a xxhdpi screen when it is placed in drawable-nodpi folder.
The code for decoding is:
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inScaled = false;
Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon, opts);
I'm drawing it in a view with canvas.
Ah, i also read other post that manifest needs to have specified minSDK and screen supports but i still seem to be unable to achieve it.
Thanks in advance!

Categories

Resources