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

有帮助吗?

解决方案

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

其他提示

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);

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top