gpt4 book ai didi

android - 如何在android中像素化位图

转载 作者:行者123 更新时间:2023-11-29 14:47:05 28 4
gpt4 key购买 nike

我一直在搜索,但我没有找到关于如何在 android 中像素化位图的问题

示例

A

注意我不是说模糊

最佳答案

您可以尝试将该图像的大小调整为较小的版本(如果出于某种原因需要它与原始图像大小相同,然后进行备份)

{
Bitmap original = ...;
//Calculate proportional size, or make the method accept just a factor of scale.
Bitmap small = getResigetResizedBitmap(original, smallWidth, smallHeight);
Bitmap pixelated = getResigetResizedBitmap(small, normalWidth, normalHeight);
//Recycle small, recycle original if no longer needed.
}

public Bitmap getResizedBitmap(Bitmap bm, int newWidth, int newHeight) {
int width = bm.getWidth();
int height = bm.getHeight();
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// CREATE A MATRIX FOR THE MANIPULATION
Matrix matrix = new Matrix();
// RESIZE THE BIT MAP
matrix.postScale(scaleWidth, scaleHeight);

// "RECREATE" THE NEW BITMAP
Bitmap resizedBitmap = Bitmap.createBitmap(
bm, 0, 0, width, height, matrix, false);
return resizedBitmap;
}

代码来自here

关于android - 如何在android中像素化位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31914565/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com