Results 1 to 8 of 8

Thread: GDI+ image to EMF (both with alpha)

  1. #1

    Thread Starter
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    GDI+ image to EMF (both with alpha)

    Ok, this is what I'm working on today. I'm not even sure where to start, but I'll be working on it while anyone interested considers this post.

    Let's say I load a PNG (with alpha channel) into a GDI+ image. How would I get that hGdipImage into an EMF, all done in memory. Also, the EMF must contain the alpha channel.

    Here's my objective: I'd like to put that EMF into a standard image control, having it show the form through the alpha layer. The EMF in an image control absolutely can be done, as shown by The Trick here.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  2. #2

    Thread Starter
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: GDI+ image to EMF (both with alpha)

    Hmmm, ok, I see code to create an EMF out of a regular bitmap image. However, I haven't figured out how to get a hGdipImage into a bitmap (and keep the alpha). It's fairly well documented that GdipCreateHBITMAPFromBitmap can't do this. Dil came up with another idea in another thread (using GdipCreateBitmapFromGdiDib), and I guess that's what I'm pursuing.

    So now, figuring out how to get from hGdipImage to DIB.
    Last edited by Elroy; Jun 25th, 2022 at 11:28 AM.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  3. #3

    Thread Starter
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: GDI+ image to EMF (both with alpha)

    Actually, GdipCreateBitmapFromGdiDib is going the wrong direction. Hmmm.

    ----------------

    Ok, what I said above is wrong. GdipCreateHBITMAPFromBitmap doesn't delete the alpha. It's the other one (GdipCreateBitmapFromHBITMAP) that deletes the alpha. Ok, this gives me something to work with.
    Last edited by Elroy; Jun 25th, 2022 at 11:28 AM.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  4. #4

    Thread Starter
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: GDI+ image to EMF (both with alpha)

    Ok, I've figured out that it's got to be an EMF+ file to have an alpha channel. Wheww, baby steps.

    -----------

    Some useful info:
    • EMF(old) and EMF+ files can encode transparency, but WMF files do not.
    • EMF+ can encode semitransparent colos, but EMF(old) cannot.
    • EMF+ format can display images more quickly than the EMF(old) format.
    • EMF+ is a newer format than EMF but both kinds of files use the same .EMF extension.
    Last edited by Elroy; Jun 25th, 2022 at 12:05 PM.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  5. #5
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: GDI+ image to EMF (both with alpha)

    Wait. . . Is EMF+ compatible with GDI and/or IPicture?

    I though that EMR_ALPHABLEND is just the macro/playback record for AlphaBlend API function call as recorded by the capturing DC.

    So it *must* be compatible with non-GDI+ plain EMF version.

    cheers,
    </wqw>

  6. #6

    Thread Starter
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: GDI+ image to EMF (both with alpha)

    Well wqweto, you tell me. I've attached an EMF file. I'm not sure, but it seems to me that it's got to be an EMF+ file because it's got translucency (non-full-transparency) in it.

    Just grab it and then directly load it into an Image control (Picture property in IDE, or LoadPicture during runtime, either way). You don't even have to run the project ... you'll see the translucency in design mode.

    Am I missing something?
    Attached Files Attached Files
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  7. #7
    Hyperactive Member
    Join Date
    Dec 2008
    Location
    Argentina
    Posts
    439

    Re: GDI+ image to EMF (both with alpha)

    I have never worked with emf but from what I saw with GdipCreateMetafileFromEmf you can pass a gdi handle to gdi+

    for file or stream reading it is not necessary to call emf's own ones, they work the same as with the other images
    (GdipCreateMetafileFromFile and GdipCreateMetafileFromStream ) ----> GdipLoadImageFromFile and GdipLoadImageFromStream

    Attachment 185184
    the results are not very encouraging, maybe you have to investigate a little more, the image with gdi+ looks very pixelated
    leandroascierto.com Visual Basic 6 projects

  8. #8

    Thread Starter
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: GDI+ image to EMF (both with alpha)

    Ok, I've think I've got it. Vlad, it was one of your old posts (inspired by The Trick) that gave me the clues.

    There was at least one bug in the code, but I found it and got it going.

    I've just now got to clean it up and make it all into something reasonable.

    I will post some examples once I get things a bit more cleaned up.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width