Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Check if a Bitmap has tranparency

Check if a Bitmap has tranparency

Scheduled Pinned Locked Moved C#
questiongraphics
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DannyAdler
    wrote on last edited by
    #1

    Hi all, So I have a Bitmap field, now I want to save it to disk, BUT if it has some transparent pixels, I want to save it as a gif, else save as jpg. Sounds reasonable? How can I do that? Thanks in advance, Danny

    C 1 Reply Last reply
    0
    • D DannyAdler

      Hi all, So I have a Bitmap field, now I want to save it to disk, BUT if it has some transparent pixels, I want to save it as a gif, else save as jpg. Sounds reasonable? How can I do that? Thanks in advance, Danny

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      There is no such thing a transparent pixels in a bitmap. There's only transparency support in file formats, and in code that sets bitmasks. The png file format has transparency built in, but when you load a bitmap object it doesn't have support for transparency, it's just not part of the format.

      Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      D 1 Reply Last reply
      0
      • C Christian Graus

        There is no such thing a transparent pixels in a bitmap. There's only transparency support in file formats, and in code that sets bitmasks. The png file format has transparency built in, but when you load a bitmap object it doesn't have support for transparency, it's just not part of the format.

        Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        D Offline
        D Offline
        DannyAdler
        wrote on last edited by
        #3

        Okay, so maybe my approach is wrong.. Situation: The user opened an image file, and I load it to a Bitmap, but I don't know if the image has some transparent regions. Now, regardless to the original user's image file's format, I want to save the image to disk, Image.Save (String, ImageFormat). So if the original image had some transparent regions, I would want to use an ImageFormat that has support for transparency (png/gif), and if there were no transparent regions, I would use Jpeg. Questions: Does this requirement make sense? How can I handle this kind of situation? Thanks, Danny

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups