Write contents of custom View to large Image file on SD card
I have a class that extends View. I override the onDraw method and allow the user to draw on the screen. I am at the point where I want to save this view as an image. I Can use buildDrawingCache and getDrawingCache to create a bitmap that I can write to the SD card. However, the image is not good quality at a large size, it has jagged edges. Since I have a View and I use Paths I can transform all by drawing to a bigger size. I just don't know how to make the Canvas bigger so when I call getDrawingCache it doesn't crop all the paths I am just transformed. What is happening is I transform all my paths but when I write the Bitmap to file I am only getting th开发者_高级运维e "viewport" of the actual screen size. I want something much bigger. Any help in the right direction would be greatly appreciated. I have been reading the docs and books and am at a loss. Thanks Jon
You can create another Canvas backed by a Bitmap that you create and draw all the paths to that. Then the Bitmap will hold the larger, higher resolution image. It would look something like this:
Bitmap largeBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas largeCanvas = new Canvas(largeBitmap);
// Draw the paths to this canvas and then use largeBitmap to save to a file.
精彩评论