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. bitmap background issue and resources

bitmap background issue and resources

Scheduled Pinned Locked Moved C#
csharpgraphicshelpquestion
5 Posts 3 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.
  • A Offline
    A Offline
    Aviv Halperin
    wrote on last edited by
    #1

    Hi, I have 2 questions regarding bitmaps: 1)I have a small bitmap (16/16 pixels) that I'm using in my application. I need to set its background to transparent. When I use the code MyBitmap.MakeTransparent(Color.White); all the white pixels become blue instead of transparent!!! Does anyone know whats going on here? 2) Is it possible to save a bitmap as part of the C# project and open it this way instead of installing the bitmap file and opening in the file way: string bmpPath = @"c:\MyBitmap"; Bitmap MyBitmap= new Bitmap(bmpPath); Thanks. avivhal

    J C 2 Replies Last reply
    0
    • A Aviv Halperin

      Hi, I have 2 questions regarding bitmaps: 1)I have a small bitmap (16/16 pixels) that I'm using in my application. I need to set its background to transparent. When I use the code MyBitmap.MakeTransparent(Color.White); all the white pixels become blue instead of transparent!!! Does anyone know whats going on here? 2) Is it possible to save a bitmap as part of the C# project and open it this way instead of installing the bitmap file and opening in the file way: string bmpPath = @"c:\MyBitmap"; Bitmap MyBitmap= new Bitmap(bmpPath); Thanks. avivhal

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      It is highly recommended that white and black not be used as transparent colors. Microsoft recommends using magenta (255, 0, 255) or green (0, 255, 0). I don't know that transparent white is the cause of your problem, though. Worth a try anyway, that is, until Heath comes along and gives you a better answer than I can.

      Tech, life, family, faith: Give me a visit. Judah Himango

      A 1 Reply Last reply
      0
      • J Judah Gabriel Himango

        It is highly recommended that white and black not be used as transparent colors. Microsoft recommends using magenta (255, 0, 255) or green (0, 255, 0). I don't know that transparent white is the cause of your problem, though. Worth a try anyway, that is, until Heath comes along and gives you a better answer than I can.

        Tech, life, family, faith: Give me a visit. Judah Himango

        A Offline
        A Offline
        Aviv Halperin
        wrote on last edited by
        #3

        Thanks, but I tried gray before and got same result. avivhal

        1 Reply Last reply
        0
        • A Aviv Halperin

          Hi, I have 2 questions regarding bitmaps: 1)I have a small bitmap (16/16 pixels) that I'm using in my application. I need to set its background to transparent. When I use the code MyBitmap.MakeTransparent(Color.White); all the white pixels become blue instead of transparent!!! Does anyone know whats going on here? 2) Is it possible to save a bitmap as part of the C# project and open it this way instead of installing the bitmap file and opening in the file way: string bmpPath = @"c:\MyBitmap"; Bitmap MyBitmap= new Bitmap(bmpPath); Thanks. avivhal

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

          1. TRy creating an imageattributes class instance and setting the transparent key on that. I didn't know bitmaps had a MakeTransparent method, I've never used it. 2. Yes, absolutely. Just make the bitmap part of your project, then change it's properties so that it is an embedded resource. Then you can load it as a resource, using code like this: private static Bitmap GetImageFromResources(string name) { // get a reference to the current assembly Assembly a = Assembly.GetExecutingAssembly(); string my_namespace = a.GetName().Name.ToString(); Bitmap image = new Bitmap(a.GetManifestResourceStream(my_namespace + "." + name)); return image; } Put that functions somewhere and call it to load your bitmaps. The name can need qualification by namespace, depending on where in the project it is. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer

          A 1 Reply Last reply
          0
          • C Christian Graus

            1. TRy creating an imageattributes class instance and setting the transparent key on that. I didn't know bitmaps had a MakeTransparent method, I've never used it. 2. Yes, absolutely. Just make the bitmap part of your project, then change it's properties so that it is an embedded resource. Then you can load it as a resource, using code like this: private static Bitmap GetImageFromResources(string name) { // get a reference to the current assembly Assembly a = Assembly.GetExecutingAssembly(); string my_namespace = a.GetName().Name.ToString(); Bitmap image = new Bitmap(a.GetManifestResourceStream(my_namespace + "." + name)); return image; } Put that functions somewhere and call it to load your bitmaps. The name can need qualification by namespace, depending on where in the project it is. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer

            A Offline
            A Offline
            Aviv Halperin
            wrote on last edited by
            #5

            Thanks. I changed the code a bit since it did not work properly. My code is: public static Bitmap GetImageFromResources(string name) { // get a reference to the current assembly System.Reflection.Assembly a = Assembly.GetExecutingAssembly(); string my_namespace = a.GetName().Name.ToString();//not needed since return assembly name string[] ResourceNames = a.GetManifestResourceNames(); string ImageFullName=""; for(int i=0 ; i < ResourceNames.Length ; i++) if(ResourceNames[i].ToUpper().IndexOf(name.ToUpper()) != -1) { ImageFullName = ResourceNames[i]; break; } Bitmap image = new Bitmap(a.GetManifestResourceStream(/*my_namespace + "." +*/ ImageFullName)); return image; } Problem was that a.GetName().Name.ToString(); does not return the name space in which the code is running but rather the assembly name. Thanks again. avivhal

            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