I’m attempting to convert the bitmap generated by the Xamarin SignaturePad component for Android to an EPS. It needs to be an EPS so that I can attach it to a LaTeX document (LaTeX only deals with EPS to my knowledge).
The code I am using to do this is as follows:
Bitmap bitmap;
try
{
bitmap = SignaturePadView.GetImage();
}
catch (Exception e)
{
MvxTrace.Trace(e.StackTrace);
Finish();
return;
}
string encodedImage;
using (var stream = new MemoryStream())
{
bitmap.Compress(Bitmap.CompressFormat.Png, 100, stream);
var bitmapData = stream.ToArray();
encodedImage = Convert.ToBase64String(bitmapData, Base64FormattingOptions.None);
}
I then take that string and send it to my server backend which decodes it into a PNG. When I do that I get what looks like a correct result, which you can see here:
If I then try to use ImageMagick to convert to an EPS like so:
convert myimage.png myimage.eps
I get an image with just a black box. To confirm this behavior I tried converting my PNG to a JPEG like so:
convert myimage.png myimage.jpg
I get the same black box as you can see here:
If I open my decoded png in Photoshop and do a “Save As JPEG” or “Save As EPS” I get what I’m looking for.
My question at this point is… what am I doing wrong? I’ve tried the same code snippet above but changed the CompressFormat to JPEG and got the same black box result. Anyone with any experience doing this kind of image conversion able to help?
2
Answers
Based on Cheesebaron's feed back I was able to track down my problem. There are two ways to fix this:
1.) Change
to
This then changes your fill color to White and thus removes the transparent background when you get the bitmap back from the signature view.
2.) Use the alpha tag with your ImageMagick convert command to remove the transparency:
It is not true that LaTeX can only embed EPS files for graphics or images. That aera is long gone…
If you have a reasonably recent LaTeX installation, you can use JPEG, PNG, TIFF and PDF (as well as EPS) to include pictures on your pages.
Anyway, to convert your PNG with ImageMagick to JPEG or EPS, try these commands: