1

I am using following for capturing signature on my application

https://github.com/Cheesebaron/MonoDroid.CaptureSignature

Its working fine if i save image as png but i want to save it in jpg

I changed Bitmap.CompressFormat.Png to Bitmap.CompressFormat.Jpg

but what i am getting is a black jpg file because the writing is in black

and the background is already black. How can i make image background white?

code i changed

using (var fs = new FileStream(extFileName, FileMode.OpenOrCreate))
{
  _capture.CanvasBitmap().Compress(Bitmap.CompressFormat.Jpg, 100, fs);
}

Looking for help. Thanks

Sam Hosseini
  • 813
  • 2
  • 9
  • 17
user1573610
  • 43
  • 1
  • 7

1 Answers1

1

I think you can only do this by setting the color on a Canvas.

See How to change the background color of a saved transparent bitmap

So you could try changing:

_capture.CanvasBitmap().Compress(Bitmap.CompressFormat.Png, 100, fs);

to something like:

var b = _capture.CanvasBitmap();
var newBitmap = Bitmap.CreateBitmap(b.Width, b.Height, b.Config);
var canvas = new Canvas(newBitmap);
canvas.DrawColor(Color.WHITE);
canvas.DrawBitmap(b, 0, 0, null);
newBitmap.Compress(Bitmap.CompressFormat.Jpg, 100, fs);

But this code is untested here - sorry!

Community
  • 1
  • 1
Stuart
  • 66,722
  • 7
  • 114
  • 165
  • untested but works great. Thanks Stuart Only thing i had to change was var newBitmap = Bitmap.CreateBitmap(b.Width, b.Height, Bitmap.Config.Argb8888); – user1573610 Oct 25 '12 at 12:01