Cant read a converted emf image bytes into metafile object

hishobhit82

New member
Joined
Aug 12, 2021
Messages
2
Programming Experience
10+
Hi,

I am using Aspose library to create an image out of the excel sheet after some processing.
This image is generated in .tiff format. With the help of C# System.Drawing library i am trying to convert this .tiff image to .emf format as its the method we use in the legacy code.
After creation of the image we are converting and saving it as base64 string.
But when we try to read this base64 string and create back the .emf image from this then we get the below error while creating the "Metafile" object.

1628757050367.png


Whereas the same object works fine when we use the Aspose.Imaging library and convert tiff to emf through aspose imaging library the same code for creating the image out of base64 string works fine. We do not want to use Aspose.Imaging as we do not have license for that. So, if anyone could please help why the conversion is not working with the C# library it would be a great help.

Also attaching the full source code to replicate the issue.
 

Attachments

  • ImageRenderIssueWithEmf.zip
    195.8 KB · Views: 14
Solution
This is a bit of a stab in the dark but try setting the Position of the MemoryStream to 0 before creating the Metafile.

Also, I think that you should be able to call Image.FromStream, so it might be worth doing that and se whether the same thing happens.

For future, reference, please don't post only screenshots of code and/or error messages. ALWAYS post code and error messages as text, formatted appropriately. If you think including a screenshot as well can add value then, by all means, do so. If someone is viewing your thread on a phone, they don't want to have to deal with screenshots and attachments.
This is a bit of a stab in the dark but try setting the Position of the MemoryStream to 0 before creating the Metafile.

Also, I think that you should be able to call Image.FromStream, so it might be worth doing that and se whether the same thing happens.

For future, reference, please don't post only screenshots of code and/or error messages. ALWAYS post code and error messages as text, formatted appropriately. If you think including a screenshot as well can add value then, by all means, do so. If someone is viewing your thread on a phone, they don't want to have to deal with screenshots and attachments.
 
Solution
This is a bit of a stab in the dark but try setting the Position of the MemoryStream to 0 before creating the Metafile.

Also, I think that you should be able to call Image.FromStream, so it might be worth doing that and se whether the same thing happens.

For future, reference, please don't post only screenshots of code and/or error messages. ALWAYS post code and error messages as text, formatted appropriately. If you think including a screenshot as well can add value then, by all means, do so. If someone is viewing your thread on a phone, they don't want to have to deal with screenshots and attachments.
Thanks for your reply. Will take care while posting in future for the screenshot.

Setting the Position to 0 did not really help.

But reading the image with Image.FromStream really worked.

Thanks a lot !
 
Back
Top Bottom