如何设置影像在ImageView的选定区域 [英] How to set selected area of Image to ImageView

查看:99
本文介绍了如何设置影像在ImageView的选定区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图设置图像图像从外部存储的ImageView 看法,我与该做的,但事情是,它的整个图像设置为 ImageView的,我只想设置从图像中选择方形区域。只是生活提供了Facebook的功能来设置用户照片.. 任何一个可以帮助我做到这一点? 以下是我想要做的样品。

I Was trying to set image to imageimageviewview from external storage and I done with that, but the thing is that it sets the whole image to imageview and I only want to set the selected square area from that image. Just life facebook provided functionality to set profile pic.. Can any one help me to do it?? Following is the sample what i want to do..

推荐答案

事情是这样的:

public static Bitmap cropBitmapToSquare(Bitmap bmp) {

    System.gc();
    Bitmap result = null;
    int height = bmp.getHeight();
    int width = bmp.getWidth();
    if (height <= width) {
        result = Bitmap.createBitmap(bmp, (width - height) / 2, 0, height,
                height);
    } else {
        result = Bitmap.createBitmap(bmp, 0, (height - width) / 2, width,
                width);
    }
    return result;
}

下面是与作物活动的样本:

Here is a sample with crop activity:

http://khurramitdeveloper.blogspot.ru/2013/07/capture-or-select-from-gallery-and-crop.html

这篇关于如何设置影像在ImageView的选定区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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