How to get the bitmap of complete scrolled area of view implemented with GestureListener with Scroller

余生长醉 提交于 2019-12-11 18:07:34

问题


What I have Tried:

I'm drawing shapeDrawables in onDraw(Canvas canvas) in a custom view with using GestureListener in view for Scroller (not scrollview). code is available on Gist

I'm trying to take the Bitmap image of that view which contains GestureListener with Scroller implementation

public void save(String fname, View view) throws FileNotFoundException {

        try {
            String filename = Environment.getExternalStorageDirectory()
                    .toString();

            File f = new File(filename, "myImage.png");
            f.createNewFile();
            System.out.println("file created " + f.toString());
            FileOutputStream out = new FileOutputStream(f);


            view.getDrawingCache();


            view.measure(view.getScrollX(), view.getScrollY());
            view.setDrawingCacheEnabled(true);
            view.getDrawingCache();
            Bitmap bitmap = Bitmap.createBitmap(view.getMeasuredWidth(),
                    view.getMeasuredHeight(), Bitmap.Config.ARGB_8888);

            bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
        } catch (Exception e) {
            e.printStackTrace();
            Toast.makeText(getApplicationContext(), e.toString(),
                    Toast.LENGTH_LONG).show();
        }
    }

Problem:

The code working fine! but what UI required is I want to take the image (screenshot) whole view which is drawing with scroller! shape drawn on out of the screen(visible on gesture Scroller) is not displayed in the image what I saved in above code. I'm failed to implement view calculations of the shape views drawn out side the initial width and and height area!

tried with this but failed:

Bitmap bitmap = Bitmap.createBitmap(
                    view.getWidth() + view.getScrollX(), view.getHeight()
                            + view.getScrollY(), Bitmap.Config.ARGB_8888);

getScrollX() returns 0 all the time !

来源:https://stackoverflow.com/questions/26542974/how-to-get-the-bitmap-of-complete-scrolled-area-of-view-implemented-with-gesture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!