Saving canvas to disk?

Put your problem here if it does not fit any of the other categories.

Saving canvas to disk?

Postby limtc » Wed Sep 23, 2009 4:27 am

Hi,
I am doing a painting program (KIds Paint - you can find in Android Market) and I have a lot of requests to save the content on disk or to wallpaper. I have been searching around but cannot find solution.

My guess is that I probably wanted to get the bitmap from the canvas, but I can't find ways to get it (why isn't there a getBitmap or capturePicture or some sort?). Then I try to set an empty bitmap into the canvas and draw on the canvas, and save the bitmap... but I got an empty bitmap.

Please help! Thanks. I would like to add the feature to the application.

Here's my codes:

public class KidsPaintView extends View {
Bitmap bitmap = null;
...

protected void onDraw(Canvas canvas) {
if (bitmap == null) {
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
canvas.setBitmap(bitmap);
}

... // do painting on canvas
}
}

Then in my main code I try to retrieve the bitmap and save it as
wallpaper:

Bitmap bitmap = view.bitmap;

try { setWallpaper(bitmap); }
catch (IOException e) { e.printStackTrace(); }

But all I got is a black wallpaper. What am I doing wrong? Or is there a better way? Thanks!
limtc
Freshman
Freshman
 
Posts: 8
Joined: Wed Sep 23, 2009 4:20 am

Top

Postby Steph » Wed Oct 28, 2009 5:07 pm

I'm sorry i don't have your answer, but i'd like to know, how you arrive to keep on your view all the draw. When i draw a second thing, the first is clear.
How do you redraw what you loose? You can save the point on view before drawing the second?

thanks in advance
Steph
Experienced Developer
Experienced Developer
 
Posts: 90
Joined: Mon Oct 20, 2008 1:48 pm
Location: France

Postby limtc » Wed Oct 28, 2009 11:24 pm

Steph wrote:I'm sorry i don't have your answer, but i'd like to know, how you arrive to keep on your view all the draw. When i draw a second thing, the first is clear.
How do you redraw what you loose? You can save the point on view before drawing the second?

thanks in advance


Oh that's a hard thing to do! You need to save the state - all the dots on screen, and redraw everytime!

I do have my answer already, you can check out Kids Paint and Simple Paint in Android Market.
limtc
Freshman
Freshman
 
Posts: 8
Joined: Wed Sep 23, 2009 4:20 am

Postby Steph » Thu Oct 29, 2009 9:08 am

I don't have android phone, so i can't download this apps (or i don't know how :/)
I'll try to find the method to do that. I hope, i'ell find if fast, because that's one of the last problem of my application.

Thanks to your help.
Steph
Experienced Developer
Experienced Developer
 
Posts: 90
Joined: Mon Oct 20, 2008 1:48 pm
Location: France

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 14 guests