Question

i draw a bitmap on my canvas , but it's not display with the original size

http://upload.dinhosting.fr/A/e/3/Sans_titre.png

this is my code :

ImageView image = (ImageView) findViewById(R.id.imageView);
Bitmap bmp1 = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
Bitmap bmp = Bitmap.createBitmap(320, 382, Bitmap.Config.ARGB_8888);
SVG svg = SVGParser.getSVGFromResource(getResources(), R.raw.carte);
Canvas canv = new Canvas(bmp);
canv.drawBitmap(bmp1,10,10,null);
Drawable[] layers = new Drawable[2]; 
layers[0] = svg.createPictureDrawable(); 
BitmapDrawable drawable = new BitmapDrawable(getResources(), bmp); 
layers[1] = drawable; 
LayerDrawable layerDrawable = new LayerDrawable(layers);
image.setImageDrawable(layerDrawable);

thnx

Was it helpful?

Solution

Bitmap

And if you use something like this:

Bitmap resizedbitmap = Bitmap.createScaledBitmap(bmp1, image.getWidth(), image.getHeight(), true);

You can get the height and width with this:
https://stackoverflow.com/a/9655670/1748764

or:

getIntrinsicWidth

getIntrinsicHeight

OTHER TIPS

Images are adjusted for size based on the device the code runs on. When you open an image, Android checks the resolution and size of the device (you use BitmapDrawable(getResources(), bmp) so the resources take into account the device.

If your image was 100x100 and you run your code on a device that has a resolution of 2.0, your image will be 200x200.

You'll need to adjust your image size to the desired width and height on your own.

Bitmap image; image=BitmapFactory.decodeResource(getResources(),R.mipmap.wallpaper);

Bitmap originalsize= Bitmap.createScaledBitmap(image, image.getWidth(), image.getHeight(), true);

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top