1

I am Windows desktop programmer that needs to convert certain SVG into EMF in order to use it for programming.

My graphics design skills are at beginner level, but I have managed to convert SVG file into EMF successfully using Inkscape. However, the result is not looking as the original one, it is less "precise" so to say. If I export the SVG as PNG the result is the same as the original file. Unfortunately I need vector format that Windows recognizes and that is only EMF ( I am using pure WinAPI and C++, hence this limitation... ).

To see exactly what I mean, link to original SVG, and EMF and PNG that I made is here. Just click on the Download:test.rar above the 5 yellow stars ( see picture below ).

enter image description here

The problem seems to be the dimensions of the EMF file ( it should be 90 x 120 ) as the picture is crystal clear when I resize my application to bigger dimensions.

I am asking your help to get the same graphic quality of the EMF file as the original SVG.

To further help you in your efforts to solve my problem, here is a small application that will display EMF in a window. Just keep the EMF in the same place the application is, and name the EMF as test.emf.

Thank you for your time and efforts. Best regards.

17
  • 1
    "to get the same graphic quality of the EMF file as the original EMF"? Aren't the originals SVGs...
    – martineau
    Aug 3 '14 at 15:05
  • @martineau: I meant "as the original SVG"... I have edited my post. Thank you for your correction. Aug 3 '14 at 16:22
  • The "precision" issue may be inherent in the EMF format (or an limitation of Inkscape's export_to_EMF functionality). You might be able to work around it by exporting the SVG files at a higher resolution (like double) and then scaling it back down when you place them using the WinAPI.
    – martineau
    Aug 3 '14 at 16:51
  • @martineau: The "precision" issue may be inherent in the EMF format -> this may well be the case because even online converters produced the same result. You might be able to work around it by exporting the SVG files at a higher resolution -> you mean if I want 100 x 100 image then I would need at least 200 x 200 SVG? Aug 3 '14 at 17:06
  • 1
    I think this was a momentary glitch with the sharing site, the link works fine now.
    – harrymc
    Aug 5 '14 at 20:51
2

I'll make a comparison with your test graphic:

  1. This is the PNG file you provide, so this probably is the desired result:

    enter image description here

  2. The output of your code, approx. at the same size:

    enter image description here

  3. The EMF file you provide, displayed in IrfanView (again approx. the same size)

    enter image description here

  4. Same as 3., but with View -> Display Options -> Use Resample turned on:

    enter image description here

Conclusion

As 4. look similar to 1. (i.e. the desired result), my conclusion is that the conversion to EMF format is perfectly fine, but your code scales the graphic with a simple, probably pixel based algorithm. So IMHO you need to implement e.g. a bilinear interpolation routine.

4
  • 2
    I have upvoted your answer, as it seems to me that you have found the problem and a solution. Still, I am little dumbstruck, shouldn't EMF be vector format, meaning not losing quality during rescale? Aug 5 '14 at 20:38
  • 1
    IrfanView does a very poor job of displaying EMF. I have also tried it and it does horrible things. I think that it converts the EMF to a small bitmap, then displays it scaled up, which causes pixelation. Image resample applies only to bitmap images, never to vector graphics which should display correctly at any size.
    – harrymc
    Aug 5 '14 at 20:48
  • 1
    @harrymc: I agree with your remarks but my app does the same ( run it and check ). this is very odd behavior indeed. I am really dumbstruck and will post a question about this on StackOverflow just to see what's wrong. Meanwhile, I ask you to try and convert SVG file into EMF with Adobe Illustrator or Photoshop, just to see how my app will behave. It will give me useful info for guys at StackOverflow. Thank you. Aug 5 '14 at 21:00
  • Can you try the same? To convert SVG into EMF with Adobe Illustrator or something else, and test it with my app? Thank you. Aug 5 '14 at 21:00
2

When viewed with Photoshop, the EMF does not have an added frame, so this seems to be a problem with the viewer.

Not able to download your viewer for some obscure reason, I have used the Free WMF Viewer to view your EMF image,

The EMF file looks perfect - it scales up and down perfectly as should a vector graphics image. But that viewer also shows a black frame around the image.

I have also viewed your EMF using an old wmf/emf viewer that I have once written, which also doesn't show the black frame. I remark that in my own viewer I have used the bounding box only to determine the aspect ratio of the image (height vs. width), so as to display it correctly, meaning not squashed or stretched.

My conclusion is that both viewers display the bounding box as a frame. This is incorrect, since its purpose is to give information about the image's recommended viewing rectangle, rather than be displayed. Your process of generating the EMF seems therefore to be correct.

5
  • I have upvoted your post because I have found documented problems for EMF on Inkscape's site ( I can't remember the link right now ). They basically say that SVG must be "simple" ( solid fills simple strokes and stuff like that ) otherwise there will be problems. As I have asked you in my comment to member mpy's answer, can you convert the SVG I uploaded into EMF with illustrator and check it with my app? Thank you. Aug 5 '14 at 21:06
  • Illustrator can display the SVG, but my version doesn't know how to save in EMF format. I note that another image painter I used asked about the size before displaying the SVG, whether to display according to a given size or according to the size of the bounding box (meaning the viewing rectangle). I think that this bounding box in the SVG is the one that is badly translated by Inkscape to EMF.
    – harrymc
    Aug 5 '14 at 21:18
  • I appreciate your efforts. SVG was created with Inkscape by converting Corel Draw file. Perhaps if I use different tool to create SVG mistakes will disappear. In my main application I display EMF exported from another program ( ArcGis ) and everything works fine. I just hope that this is some bug with Inkscape and not larger issue I must solve. Thank you, we shall "talk" again soon. Aug 5 '14 at 21:22
  • I have tried an old wmf/emf viewer that I have once written, and it also doesn't show the black frame. I remark that I have used there the bounding box only to determine the aspect ratio of the image (height vs. width) so the image is displayed correctly. I still think that the viewers that display it interpret that box incorrectly, since its purpose is not to be displayed.
    – harrymc
    Aug 7 '14 at 9:20
  • I have downloaded Adobe Illustrator ( trial version ) and exported original EPS file inot EMF. The result remained the same. Asking for help at StackOverflow, I got an answer that manipulated the file before showing it. This means that the problem is in the way my framework outputs the file. Therefore I have decided to accept the other answer ( I have upvoted yours earlier ). Thank you for your time and help, I highly appreciate it. Aug 17 '14 at 18:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.