bitmap background issue and resources
-
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
-
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
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
-
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
Thanks, but I tried gray before and got same result. avivhal
-
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
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 -
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 StringerThanks. 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