【发布时间】:2014-06-08 11:42:04
【问题描述】:
我正在尝试缩放位图,我希望它们可以在所有安卓手机上工作。我在这个网站上看到了这段代码,但我不确定如何以及在哪里将这段代码应用到我的应用中。:
代码:
Bitmap image1, pic1;
image1 = BitmapFactory.decodeResource(getResources(), R.drawable.image1);
float xScale = (float) canvas.getWidth() / image1.getWidth();
float yScale = (float) canvas.getHeight() / image1.getHeight();
float scale = Math.max(xScale, yScale); //selects the larger size to grow the images by
scale = (float) (scale*1.1); //this allows for ensuring the image covers the whole screen.
scaledWidth = scale * image1.getWidth();
scaledHeight = scale * image1.getHeight();
pic1 = Bitmap.createScaledBitmap(image1, (int)scaledWidth, (int)scaledHeight, true);
然后我也从这个网站看到了这段代码
http://developer.sonymobile.com/2011/06/27/how-to-scale-images-for-your-android-application/
最后一次更新似乎是在 2011 年。
有人能解释一下哪种方法更适合 API10 或 > 等新 API 吗?
我知道现在有 API19,所以我确信肯定会有这些的新版本和更好的版本。
您愿意与我们分享您的知识和善意吗?
非常感谢您。
【问题讨论】:
标签: scaling image-scaling android-bitmap