canvas size Increases the Bitmap Size android - android

Bitmap icon = BitmapFactory.decodeResource(this.getResources(),R.raw.book11);
Canvas c = new Canvas(icon);
using this line of code for making canvas actually increases the size of the canvas(150x177) from the bitmap(100x118). If I use predefining the size of canvas, the bitmap gets cropped. Help please.
thanks.

I solved mine with this equation:
event.getX()*3/2;
event.getY()*3/2;

the system will automatically up-scale your image asset when you use it for a 'larger/higher' screen resolution/density if that particular asset is missing for that particular configuration (i.e. you're referencing an image on a hdpi device while that image is not present in the drawable-hdpi but only in raw drawable directory).
Note that scaling factor depends on device's screen density. In your case that seems to be 1.5.
EDIT: If not done yet, please check the link.

Related

Resize png icon inside Android Studio / IntellIJ

I want a way to resize png icon inside Android Studio, so that I have not resize it from external source. Please note I am not talking about to code. I want resize png icon. (Like 100*100 to 50*50)
Any plugin/ In AS way you know about?
If you mean resizing in code, then you need to get a bitmap from either bitmap drawable / resource stream directly.
Bitmap.createScaledBitmap(yourBitmap, yourWidth, yourHeight, false)
This will scale your bitmap.
If you wanted to get different image size for different density, you are looking for https://plugins.jetbrains.com/plugin/7658-android-drawable-importer, which allows you to batch import your image file and scale your image into different sizes for different dpi.
If you are looking for editing to raw png size, you need to use external tools.

PIcture size 4 times actual image

I'm making an Android game.
I loaded a 128x240 PNG image with my sprites into a Bitmap object and tried to retrieve a 16x16 tile from it via createBitmap(bitmap, x, y, w, h), but got a 1/4 smaller section of the picture instead.
The width/height of the picture according to getWidth/getHeight is 512x960.
What am I doing wrong?
Probably you have the picture in your drawable folder and testing it on a device with high resolution? Android automatically scales up pictures according to http://developer.android.com/guide/practices/screens_support.html
I think the quick solution is to put the image to a drawable-xhdpi (or according other drawable folder).
EDIT: based on a comment at I don't want Android to resize my bitmap Automatically, you can add a folder "drawable-nodpi" to prevent the resizing

Load big size image issue in imageview . Bitmap too large to be uploaded into a texture

I have 270 x 2693 pixel image in drawable folder . When i try to set that image in imagview i got Bitmap too large to be uploaded into a texture warning.
Image sets perfectly in android device < 4.0 but not sets > 4.0 device.
Please help me to resolve this issue.
Code
<ImageView
android:id="#+id/imageView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:contentDescription="#string/name"
android:src="#drawable/hindi" />
Here hindi is a image in drawable folder and its size is 270 x 2693 pixel.
Problem
This problem is usually related either to OpenGL maximum texture size or the Device Memory. The full error you are getting is probably something like
W/OpenGLRenderer(12681): Bitmap too large to be uploaded into a texture (270x2693, max=2048x2048)
Memory is generally the problem with a large scale image but in your case 270x2693 is 727110 pixels. If you are in RGBA, it's 4 bytes per pixel so 727110 * 4 = 2908440 bytes, which is approximately 2,7 megabytes. That should fit on any devices.
Thus, your problem is probably related to OpenGL. What might happen is that the Android device > 4.0 you are testing on detect that your image is too large for OpenGL and resize it for you, while older devices don't.
Edit:
In my case, the problem is that my 640x1136 splash image seems to get rezised automatically to a 1280x2272 image size to fit my device huge screen. Which also triggers the error message you are having.
If you get this error further on, it is related to the dpi that is used to load the image. As you will find on Android reference, device will load image regarding their dpi which can alter the size of image that is loaded in memory.
Solution
You don't have much choice other than detecting the device size to
load the image properly.
See how to load large bitmap in memory.
You can also use different image size for different device dpi which
can be automatically selected from the Drawable folder by Android.
See the How to support screens which tells you how to setup your
folder.
As other stated, use a smaller image or reduce its size.
Related informations
I suggest you have a look there if you need to support multiples screens.
Android also collect data which are updated every 7 days on Screens size among their users.
Also have a look to this interesting answer which points out a good website to understand Image Size in memory.
Finally, if you are already using OpenGL in your app, have a look to this answer which shows how to detect the max OpenGL texture size.
Why not reduce the size of the image? If you don't want to do that, then rather than specify the bitmap in the XML, load it from program code, and scale it to fit the display. See this guide for more information on loading large bitmaps.
try use this code
int[] maxTextureSize = new int[1];
GLES10.glGetIntegerv(GL10.GL_MAX_TEXTURE_SIZE, maxTextureSize, 0);
maxTextureSize stores the size limit for decoded image such as 4096x4096, 8192x8192 . Remember to run this piece of code in the MainThread or you will get Zero.

Create Bitmap from View in Android

I want to create a bitmap from a view in Android, which basically works fine using the following approach: http://www.aquajava.hu/2011/06/19/converting-view-to-bitmap-without-displaying-it/
However, I want to modify this approach. Basically, my application supports multiple display densities for all kinds of resolution. Instead of creating a bitmap from a view based on the device's display, I want that the bitmap created always relies on the HDPI version. So although the display is maybe smaller I want to create a bitmap with 480 * 800 pixels. If I just increase the size of the bitmap, the font sizes and images still stay small according to the density. I don't want to just scale the image because the resolution would be quite poor then.
So basically, I search for a way to create a bitmap from a view ignoring the density of the view.
Does anybody know how I can solve this?
Have you tried calling setDensity on your Bitmap?

Android - Setting a bitmap as the wallpaper

As part of this application I am making, I want to change my wallpaper on my android device based on a bitmap that the user has selected.
I am able to change the background. However, the background is a completely distorted version of the bitmap. Any idea as to why this would happen?Here is my code:
Bitmap bitmap = ((BitmapDrawable)currentDrawable).getBitmap();
this.setWallpaper(bitmap);
My bitmap has a width of 240px and height of 180px. My emulator is of a size 480px by 800px.
I can scale my bitmap to 480px. However, the bitmap still ends up being distorted on the android wallpaper. Any thoughts on how this can be fixed?
Thanks in advance
You should create multiple images, for each potential (and common) resolution. You don't want any scaling, or the image will be distorted.
UPDATE:
Here is a ton of good information on support multiple screen sizes:
http://developer.android.com/guide/practices/screens_support.html
The wallpaper used by the default Launcher is bigger than the actual screen, that's why you can scroll the content and the wallpaper too.

Categories

Resources