问题
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;
}
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.
回答1:
you can accomplish this using this library use cropimageview3 and set your image in float drawable and you are done
回答2:
"You're doing it wrong".
Instead of creating new Bitmap
each time, you have several options:
- Resize
ImageView
itself. - Create your own
View
and draw bitmap usingCanvas
. This will let you stretchBtimap
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:
onTouchEvent
- to handle your resize behaviour, when user touches crop points.onMeasure
- to slightly increase size of yourView
, because your "crop-points" slightly comes out of image.
来源:https://stackoverflow.com/questions/17971884/how-to-create-resizable-imageview-in-android