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
Related
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);
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.
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()
I would like to create an image chooser from my drawable resources. I think I have found an "easy" way to do this. I was going to create a listview that displays the drawables , and the user would be able to pick one. I would then pass back , the path to this drawable resource, the paths would be hard-coded in. I then would set a bitmap to this drawable path. I was trying to do a simple test of this with just hard coded values, (no listview yet) but I do not get a visible bitmap back. I think it "works" , but maybe the bitmap is to small or not set to visible?
bm2 = BitmapFactory.decodeFile("/gds2/res/drawable-hdpi/feel_like_a_sir.png");
foreground_imageview.setImageBitmap(bm2);
Try to load your drawable in this way
bm2 = BitmapFactory.decodeResource(getResources(), R.drawable.feel_like_a_sir);
foreground_imageview.setImageBitmap(bm2);
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!