如何调整图像(位图),以给定大小? [英] How to resize image (Bitmap) to a given size?
本文介绍了如何调整图像(位图),以给定大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何调整图像(位图),以例如800 * 480编程?我检索到我的应用程序的图片是〜1MB,我需要向下扩展到800 * 480 我已经加载的画面和COM pressed,但我怎么做,使之更小:
ByteArrayOutputStream BOS =新ByteArrayOutputStream(8192);
photo.com preSS(比较pressFormat.JPEG,25,BOS);
解决方案
位图scaledBitmap = scaleDown(realImage,MAX_IMAGE_SIZE,真正的);
//缩减法
公共静态位图scaleDown(位图realImage,浮maxImageSize,
布尔过滤器){
流通股比例= Math.min(
(浮点)maxImageSize / realImage.getWidth()
(浮点)maxImageSize / realImage.getHeight());
INT宽度= Math.round((浮动)比* realImage.getWidth());
INT高= Math.round((浮动)比* realImage.getHeight());
位图newBitmap = Bitmap.createScaledBitmap(realImage,宽度,
高度,过滤器);
返回newBitmap;
}
How to resize image (Bitmap) to for example 800*480 programatically ? I have retrieved a picture in my app which is ~1MB and I need to scale it down to 800*480 I have loaded that picture and compressed it but how do I do to make it smaller :
ByteArrayOutputStream bos = new ByteArrayOutputStream(8192);
photo.compress(CompressFormat.JPEG, 25, bos);
解决方案
Bitmap scaledBitmap = scaleDown(realImage, MAX_IMAGE_SIZE, true);
//scale down method
public static Bitmap scaleDown(Bitmap realImage, float maxImageSize,
boolean filter) {
float ratio = Math.min(
(float) maxImageSize / realImage.getWidth(),
(float) maxImageSize / realImage.getHeight());
int width = Math.round((float) ratio * realImage.getWidth());
int height = Math.round((float) ratio * realImage.getHeight());
Bitmap newBitmap = Bitmap.createScaledBitmap(realImage, width,
height, filter);
return newBitmap;
}
这篇关于如何调整图像(位图),以给定大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文