【发布时间】:2013-12-31 19:24:34
【问题描述】:
我希望我的应用程序的用户能够在运行时修改图像。用户应该能够通过点击图像视图的角并拖动它来修改图像的高度和宽度,如下图所示:
我花了很多时间对此进行研究,发现 Making Sense of Multitouch 和 Resize a large bitmap file to scaled output file 类似于 Pinch Zoom,但这些都不符合我的要求。
目前我正在使用下面的函数调整位图的大小,并在 seekbar 的 onprogress 更改方法中更改宽度而不是 frame。使用此功能更改图像大小并不顺利。
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;
}
更新:
现在使用this问题的公认答案在画布中使用绘图位图顺利工作。
现在铰孔部分正在将图像周围的框架设置为类似于裁剪框架的东西。
请帮助我实现这一目标。
【问题讨论】:
-
嗨,我看过教程,但我想问你:位于图像两侧的点是否只允许 X 轴或 Y 轴移动?如果是这样,那么您不能在代码部分中将
// Calculate the distance moved简单地调整 X 和/或 Y 轴上的图像大小并将其更新为ImageView吗? -
no point is not located.此帧应在重新缩放后根据图像大小出现。所以这个框架应该每次都在图像周围动态生成。我改变了我的问题图像。请检查这个新图像。谢谢...
-
我猜有积分的部分已经完成了?你有没有为此做过什么?
-
框架现在没有实现。首先,我尝试只考虑宽度。我放了搜索栏而不是框架来增加和减少宽度。我已经使用 decodeFile 函数来重新调整位图的大小并将其设置为 imagview。但位图变化如此缓慢,因此无法顺利运行。我可以像捏缩放那样获得平滑度吗?
-
您的问题到底是什么?你试过写点什么吗?
标签: android bitmap image-resizing