[英]How to reduce resolution of bitmap
我有一些图像为 bitmap,
我想降低图像的分辨率,以便更容易使用(用于计算所有像素)。
如何降低分辨率并创建一个新的bitmap来使用?
使用@blackapps 评论和使用@Padma Kumar 的答案解决了这个问题如何将图像(位图)调整为给定大小?
Bitmap scaledBitmap = scaleDown(realImage, MAX_IMAGE_SIZE, true);
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;
}
现在它起作用了!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.