Canvas.SetBitmap and redraw

BobSmithBobSmith Robert SmithAUMember
edited March 2013 in Android

I am trying to capture the screen after I have done the main drawing so I can efficiently redraw the screen with some simple changes after the screen touch event has fired. But All I am getting is a black screen with the simple changes on top.

I am using

ScreenBitmap = Bitmap.CreateBitmap(Width, Height, Bitmap.Config.Argb8888);
Canvas.SetBitmap(ScreenBitmap); // the Canvas where everything was drawn to

to test i am saving the image to file with, it is creating an image file that is totally black

FileStream fs = new FileStream("mnt/sdcard/Download/screenshot.jpg", FileMode.Create, FileAccess.Write);
ScreenBitmap.Compress(Bitmap.CompressFormat.Jpeg, 80, fs);

then to redraw I am using

Canvas.DrawBitmap(ScreenBitmap, 0, 0, null);

any help will be greatly appreciated

Posts

  • BobSmithBobSmith Robert Smith AUMember

    I have figured out how to do it. I was going about it all wrong. The way to do it is create a Canvas with the Bitmap constructor. The Bitmap should be the same size as your view. Then draw to this "bitmap canvas". Then to draw to the View, just draw the bitmap to the real screen Canvas.

    The code I used is. ScreenBitmap = Bitmap.CreateBitmap(Canvas.Width, Canvas.Height, Bitmap.Config.Rgb565); BitmapCanvas = new Canvas(ScreenBitmap); // then draw to the Canvas.

    Then to draw to real canvas Canvas.DrawBitmap(ScreenBitmap, 0, 0, null);

Sign In or Register to comment.