作者:Tow-face信信 | 来源:互联网 | 2023-05-18 12:49
I am trying to take an image like these
我想拍这样的照片
and turn them into the top right 1/4 of the image. The image below is an example of what I need.
把它们变成图像的右上角1/4。下面的图片是我需要的一个例子。
**UPDATE: **
* *更新:* *
I have it (sort of) working, but scaling the image creates an unacceptable amount of distortion my code seems terribly inefficient. Any ideas on how to improve this code or a possible better approach?
我让它(某种程度上)工作,但是扩展映像会造成不可接受的程度的失真,我的代码似乎非常低效。对于如何改进这段代码或可能更好的方法有什么想法吗?
I am subclassing Volley's NetworkImageView.
我正在细分Volley的NetworkImageView。
Here is my code
这是我的代码
public static Bitmap getCroppedBitmap(Bitmap bmp, int radius) {
Bitmap sbmp;
if (bmp.getWidth() != radius || bmp.getHeight() != radius) {
float smallest = Math.min(bmp.getWidth(), bmp.getHeight());
float factor = smallest / radius;
sbmp = Bitmap.createScaledBitmap(bmp, (int) (bmp.getWidth() / factor), (int) (bmp.getHeight() / factor),
false);
} else {
sbmp = bmp;
}
Bitmap output = Bitmap.createBitmap(radius, radius, Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xffa19774;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, radius, radius);
paint.setAntiAlias(true);
paint.setFilterBitmap(true);
paint.setDither(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(Color.parseColor("#BAB399"));
canvas.drawCircle(radius / 2 + 0.7f, radius / 2 + 0.7f, radius / 2 + 0.1f, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(sbmp, rect, rect, paint);
Bitmap bitmap = Bitmap.createBitmap(output, output.getWidth() / 2, 0, output.getWidth() / 2,
output.getHeight() / 2);
Bitmap scaledBmp = Bitmap.createScaledBitmap(bitmap, radius, radius, true);
return scaledBmp;
}
3 个解决方案