如何在Android中创建可调整大小的ImageView [英] How to create resizable ImageView in Android

查看:684
本文介绍了如何在Android中创建可调整大小的ImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的应用程序的用户能够在运行时修改图像.用户应该能够通过点击图像视图的一角并拖动它来修改图像的高度和宽度,如下图所示:

I want a user of my app to be able to modify an image at run time. The user should be able to modify the image height and width by tapping on the corner of the image-view and dragging it as illustrated in the following diagram:

我花了很多时间对此进行研究,发现将大的位图文件调整为缩放后的输出文件大小,例如捏缩放",但这些都不完全符合我的要求.

I have spent a lot of time researching this and I found Making Sense of Multitouch and Resize a large bitmap file to scaled output file something like Pinch Zoom but none of these quite match my requirements.

目前,我正在使用以下功能调整位图的大小,并在搜索栏的渐进式更改方法(而不是帧)中更改宽度.通过使用此功能,更改图像大小无法正常工作.

currently i am resizing bitmap using this below finction and changing width in onprogress change method of seekbar instead of frame. by using this function changing image size is not working smooth.

public static Bitmap decodeFile(File f,int WIDTH,int HIGHT){

    try {
        //Decode image size
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(new FileInputStream(f),null,o);

        //The new size we want to scale to
        final int REQUIRED_WIDTH=WIDTH;
        final int REQUIRED_HIGHT=HIGHT;

        //Find the correct scale value. It should be the power of 2.
        int scale=1;
        while(o.outWidth/scale/2>=REQUIRED_WIDTH && o.outHeight/scale/2>=REQUIRED_HIGHT)
            scale*=2;

        //Decode with inSampleSize
        BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inSampleSize=scale;
        return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
    }
        catch (FileNotFoundException e) {}
    return null;

}

更新:

现在使用此的可接受答案,在画布中使用绘图位图来顺利工作问题.

Now working smoothly using drawing bitmap in canvas using accepted answer of this question .

现在扩孔的部分是将图像周围的帧设置为类似于裁剪帧之类的东西.

now reaming part is setting frame around image as something like crop frame.

请帮助我实现这一目标.

Please help me to achieve this.

推荐答案

您可以使用使用cropimageview3并将图像设置为float drawable,就可以完成

you can accomplish this using this library use cropimageview3 and set your image in float drawable and you are done

这篇关于如何在Android中创建可调整大小的ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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