问题
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