我在画布上绘制了一个位图,但它没有以原始大小显示
http://upload.dinhosting.fr/A/e/3/Sans_titre.png
这是我的代码:
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
答案 0 :(得分:1)
如果你使用这样的东西:
Bitmap resizedbitmap = Bitmap.createScaledBitmap(bmp1, image.getWidth(), image.getHeight(), true);
你可以用这个得到高度和宽度:
https://stackoverflow.com/a/9655670/1748764
或:
答案 1 :(得分:0)
根据运行代码的设备调整图像的大小。当您打开图像时,Android会检查设备的分辨率和大小(使用BitmapDrawable(getResources(),bmp),因此资源会考虑设备。
如果您的图片是100x100,并且您在分辨率为2.0的设备上运行代码,则您的图片将为200x200。
您需要自行调整图像大小到所需的宽度和高度。
答案 2 :(得分:0)
位图图像; 图像= BitmapFactory.decodeResource(getResources(),R.mipmap.wallpaper);
Bitmap originalsize = Bitmap.createScaledBitmap(image,image.getWidth(),image.getHeight(),true);