裁剪图像在android的特定部分 [英] Crop particular part of image in android

查看:128
本文介绍了裁剪图像在android的特定部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从下面的图像裁剪红色部分,有没有简单的方法,在Android中使用,可以裁剪下面的图片。

I want to crop Red part from following image, Is there any simple method available in android that can crop following image.

我发现有很多做题但都建议要使用下面的code:

I have found many SO questions but all are suggesting to used following code:

Bitmap croppedBitmap = Bitmap.createBitmap(bitmapOriginal, 100, 100,100, 100); 

这code工作做好,如果宽度放大器;身高大约200万像素的分辨率,但如果裁剪部分超过比应用300万像素的分辨率得到了开车撞OOM错误。

This code work well if width & height are around 2MP resolution, but if that cropped part is more than 3MP resolution than application got crashed with OOM error.

有没有什么办法可以处理图像比300万像素以上裁切过程中?

Is there any way that handle image more than 3MP during cropping?

推荐答案

您可以用以下code,可以解决你的问题。

You can used following code that can solve your problem.

Matrix matrix = new Matrix();
matrix.postScale(0.5f, 0.5f);
Bitmap croppedBitmap = Bitmap.createBitmap(bitmapOriginal, 100, 100,100, 100, matrix, true);

以上方法做形象postScalling裁剪之前,所以你可以用裁剪图像最好的结果没有得到OOM错误。

Above method do postScalling of image before cropping, so you can get best result with cropped image without getting OOM error.

有关详细可以参考这个博客

这篇关于裁剪图像在android的特定部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆