我使用通用图像加载程序加载图像,并且我想缩放它,以便宽度是屏幕的宽度并且相应地缩放高度,这意味着之前我加载图像我知道我想要的宽度,但不是高度。所以当我加载图像时,我想要获取图像的高度和宽度,并使用它根据屏幕宽度进行缩放。我用它来做到这一点的代码是这样的:使用通用图像加载程序加载后调整位图大小
try {
display.getSize(size);
scaledWidth = size.x;
} catch (java.lang.NoSuchMethodError ignore) {
scaledWidth = display.getWidth();
}
String filePath = "file://" + getBaseContext().getFilesDir().getPath().toString() + "/" + imagePath + ".png";
Bitmap bitmap = imageLoader.loadImageSync(filePath);
int height = bitmap.getHeight();
int width = bitmap.getWidth();
scaledHeight = (int) (((scaledWidth * 1.0)/width) * height);
//Code to resize Bitmap using scaledWidth and scaledHeight
什么是使用通用图像装载机,甚至更好的调整位图的最好办法,是没有办法,我只能指定宽度的方式和位图进行缩放正确地基于它的比例?
http://stackoverflow.com/questions/4837715/how-to-resize -a-bitmap-in-android – kupsef
我建议你使用[毕加索图书馆](http://square.github.io/picasso/)。它允许非常简单的图像加载和操作,同时仍然灵活。 –
我的解决方案基于@ nitesh-goel代码和@zhaoyuanjie'DisplayImageOptions',但是具有'ImageScaleType.EXACTLY_STRETCHED'。请注意,如果您将图片放大太多,图片看起来会模糊不清。 – Leukipp