9

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:

enter image description here

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;

}

UPDATE :

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.

Community
  • 1
  • 1
Sanket Kachhela
  • 10,861
  • 8
  • 50
  • 75
  • Hi, I saw the tutorial, but let me ask you this: Are the point situated on the sides of the image permitting only X or only Y axis movement ? If so, then Can't you put, in the section of the code where `// Calculate the distance moved` a simple resizing of the image on X and/or Y axis and updating this to the `ImageView` ? – g00dy Jul 31 '13 at 13:57
  • no point is not situated.this frame should come as per image size after rescaling. so this frame should have to generate dynamically every time around image. i changed my question image. plz check this new image. thanks... – Sanket Kachhela Jul 31 '13 at 14:08
  • I guess that the part with the points is already done? Have you done anything for this yet or not ? – g00dy Jul 31 '13 at 14:34
  • The frame is not implemented right now. first i have try to just for width. i have put seekbar instead of frame to increase and decrease width. i have use decodeFile function to re-size bitmap and setting it into imagview. but bitmap change so slowly so it is not working smooth. can i get smoothness as we do in pinch zoom? – Sanket Kachhela Jul 31 '13 at 14:45
  • What is your problem exactly? Had you tried to write something? – Dmitry Zaytsev Jul 31 '13 at 16:12
  • Did you solve this? Do you have other references on how to do this? – MMakati Nov 05 '13 at 07:20
  • @SanketKachhela : have you solved this problem? if yes then can you share your sample code? – Biginner Nov 25 '14 at 14:24

2 Answers2

1

"You're doing it wrong".

Instead of creating new Bitmap each time, you have several options:

  1. Resize ImageView itself.
  2. Create your own View and draw bitmap using Canvas. This will let you stretch Btimap as you want.

If you'll go with Canvas, then to display those "crop-points" you can just also draw them on your canvas. Althought, to achieve desired behaviour and appearance you probably will need to override those methods as well:

  1. onTouchEvent - to handle your resize behaviour, when user touches crop points.
  2. onMeasure - to slightly increase size of your View, because your "crop-points" slightly comes out of image.
Dmitry Zaytsev
  • 23,650
  • 14
  • 92
  • 146
1

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

Maulik.J
  • 636
  • 1
  • 6
  • 14