【发布时间】:2012-06-11 23:42:39
【问题描述】:
我有一个使用来自 Pragmatic Bookshelf 的 Touch V2 示例加载的位图图像的 RelativeLayout -- http://media.pragprog.com/titles/eband3/code/Touchv2/src/org/example/touch/Touch.java
我添加了一个带有 onclicklistener 的单独按钮,单击该按钮时将从图库中加载图像。在活动结果中,图像作为位图加载到 RelativeLayout:
public void getPictureFromFile(Uri targetUri){
try {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = scale(getContentResolver()
.openInputStream(targetUri));
workinprogress = BitmapFactory.decodeStream(
getContentResolver().openInputStream(targetUri),
null, options);
view.setImageBitmap(workinprogress);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
单击下一个按钮,我使用以下方法获取相对布局的图像:
thepicture.buildDrawingCache(true);
Bitmap bm = Bitmap.createBitmap(thepicture.getDrawingCache());
这个过程非常棒——对于第一张图片。当我再次加载另一个图像时,传递的位图仍然与原始图像相同。我在 getDrawingCache() 之前尝试了 thepicture.invalidate() 和 thepicture.resetDrawableState() 但似乎都没有将图像更新为新加载的图片,尽管框架布局显示了正确的图像。
对于我加载的第二张图片,我需要为刷新drawingCache 实现什么我不明白的地方吗?
【问题讨论】: