skip to Main Content

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:

enter image description 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:

enter image description 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


  1. Chosen as BEST ANSWER

    Based on Cheesebaron's feed back I was able to track down my problem. There are two ways to fix this:

    1.) Change

    bitmap = SignaturePadView.GetImage();
    

    to

    bitmap = SignaturePadView.GetImage(Color.Black, Color.White);
    

    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:

    convert -alpha background myimage.png test.jpg
    

  2. 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:

     convert http://i.stack.imgur.com/Uxcm7.png -alpha remove UXcm7.eps
     convert http://i.stack.imgur.com/Uxcm7.png -alpha remove UXcm7.jpg
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search