scoubidou944
Messages postés714Date d'inscriptionmardi 22 avril 2003StatutMembreDernière intervention19 janvier 2017
-
2 mars 2005 à 21:57
TheSaib
Messages postés2367Date d'inscriptionmardi 17 avril 2001StatutMembreDernière intervention26 décembre 2007
-
3 mars 2005 à 00:47
On a vu dans un topic validé récemment que :
this.Image =
new Bitmap( GetType(),
"resources.LED_Red.png");
Permettait d'afficher une image avec transparence alpha (cad avec dégradé de teintes).
Maintenant, si on veut faire de meme avec une imagelist :
this.m_oAdditionalImageList.Images.Add (
new Bitmap( GetType(),
"resources.LED_Red.png"));
ou
this.m_oAdditionalImageList.Images.Add (Image.FromFile (
@".\resources\LED_Green.png"));
bah ca marche po :(
une idée de ce que G zappé ?
----------------------------
C++ forever
C# amateur
TheSaib
Messages postés2367Date d'inscriptionmardi 17 avril 2001StatutMembreDernière intervention26 décembre 200723 3 mars 2005 à 00:47
An imagelist is a single bitmap onto which the component images are copied
when they're added. The alpha component is not maintained in the addition
process so unless the image is on a colour keyed background and the
imagelist.TransparentColor correctly set, the images will be opaque.
This is intended behaviour and ImageLists are not suitable for images having
per-pixel alpha values such as that available in PNG.
<SUP>Some of you may have seen the solution of using ImageList's with Manifest
files, but the more astute of you will notice that the alpha transparency is
actually being converted to full indexed transparency. So the horrible black
is gone but the smooth edge has also (similar to how IE handles palletised
PNG file with alpha transparency even with the DX filter).
A solution to this is to use the Icon class and then use the DrawIcon method
of the Graphics class to draw the icon when the paint event fires on the
form. eg:
protected override void OnPaint(PaintEventArgs e)
{
Stream myIconStream = ...... (stream to your icon file or resource)
Icon myIcon = new Icon(myIconStream); // if you want to change the size
look at the icon constructor
e.Graphics.DrawIcon(myIcon,16,16); //this is the position on the form not
the size
}
Now some of you will know that the Icon class has a bug of using 16 colour
icons below desktop colour depths of 32bit. To solve this problem use the
User32.dll::LoadImage function to get a handle (hicon). eg:
[System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
private static extern IntPtr LoadImage(
int Hinstance,
string name,
int type,
int width,
int height,
int load);
protected override void OnPaint(PaintEventArgs e)
{
// Get a handle to an icon.
IntPtr Hicon = LoadImage(
0,
"myIcon.ico",
1,
32, // width
32, // height
8208);//this is what it's meant to be or could just be 16 see Platform
SDK
Now the last bug that I have found is that the resource compiler (rc.exe)
that ships with Visual studio corrupts the 32x32 Alpha Icon on compilation
(.res). I still havn't fixed this yet but most of you probably won't need
win32res icons as you will be using .NET resource files (.resx)</SUP>