view.getDrawingCache()只能一次 [英] view.getDrawingCache() only works once

查看:438
本文介绍了view.getDrawingCache()只能一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用从语书架触摸V2例如加载的位图图像RelativeLayout的 - <一个href="http://media.pragprog.com/titles/eband3/$c$c/Touchv2/src/org/example/touch/Touch.java">http://media.pragprog.com/titles/eband3/$c$c/Touchv2/src/org/example/touch/Touch.java

I have a RelativeLayout with a loaded bitmap image using the Touch V2 example from Pragmatic Bookshelf -- http://media.pragprog.com/titles/eband3/code/Touchv2/src/org/example/touch/Touch.java

我添加了一个单独的按钮,onclicklistener,当点击将加载图像从画廊。在活动结果的图像加载为位图到RelativeLayout的:

I've added a separate button with onclicklistener that when clicked will load an image from the gallery. On the activity result the image is loaded as a bitmap into the 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();
    }
}

一单击Next按钮,我抢RelativeLayout的形象使用:

One the next button click, I grab the image of the relativelayout using:

                thepicture.buildDrawingCache(true);
            Bitmap bm = Bitmap.createBitmap(thepicture.getDrawingCache());

这个过程是了不起的 - 在第一张图像。当我再次加载另一幅图像,通过位图仍和原来一样。我试过thepicture.invalidate()和thepicture.resetDrawableState()getDrawingCache(前),但似乎都不更新形象的新加载的图片,虽然框架布局显示正确的图像。

The process works terrific -- for the first image. When I load another image again, the bitmap passed is still the same as the original. I've tried the thepicture.invalidate() and thepicture.resetDrawableState() before getDrawingCache() but neither seem to update the image to the newly loaded picture, although the frame layout displays the correct image.

有什么我不明白有关刷新drawingCache,我需要实现第二图像我加载?

Is there something I don't understand about refreshing drawingCache that I need to implement for the second image I load?

推荐答案

我不认为答案仍然是迫切需要你,但可能是其他人面临这样的问题,所以...

I don't think the answer is still urgent for you, but may be someone else faced such problem, so...

要使其工作更加那么,一旦你必须使用 view.setDrawingCacheEnabled(真)每次前后 view.setDrawingCacheEnabled(假)调用后每次 view.getDrawingCache()。见例如:

To make it work more then once you have to use view.setDrawingCacheEnabled(true) each time before and view.setDrawingCacheEnabled(false) each time after calling view.getDrawingCache(). See the example:

imageView.setDrawingCacheEnabled(true);
imageView.buildDrawingCache(true);
File imageFile = new File(Environment.getExternalStorageDirectory(),
        "Pictures/image.jpg");
FileOutputStream fileOutputStream = new FileOutputStream(imageFile);
imageView.getDrawingCache(true).compress(CompressFormat.JPEG, 100,
        fileOutputStream);
fileOutputStream.close();
imageView.setDrawingCacheEnabled(false);

这篇关于view.getDrawingCache()只能一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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