neo2k2
Messages postés126Date d'inscriptionjeudi 16 janvier 2003StatutMembreDernière intervention 9 novembre 2009
-
13 oct. 2008 à 12:29
cs_Willi
Messages postés2375Date d'inscriptionjeudi 12 juillet 2001StatutModérateurDernière intervention15 décembre 2018
-
20 oct. 2008 à 19:08
Bonjour, cette question étant souvent abordée, je vous la repose néanmoins avec mon code afin que l'on puisse m'expliquer et/ou corriger ce qui ne va pas.
Est-il correct d'utiliser System.Drawing.Bitmap("test.bmp") pour obtenir une image (que j'ai appelée par exemple test.bmp) contenue dans ma picturebox ou mon problème vient-il de là? Faut-il plutôt un png?
Merci d'avance à tous!
private void pictureBox1_OnPaint(object sender, EventArgs e)
{
// Create a red and black bitmap to demonstrate transparency.
System.Drawing.Image bmp = new System.Drawing.Bitmap("test.bmp");
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);
// Detect image attributes
System.Drawing.Imaging.ImageAttributes attr = new System.Drawing.Imaging.ImageAttributes();
// for a color from the bitmap
attr.SetColorKey(bmp.GetPixel(0, 0), bmp.GetPixel(0, 0));
// for a color from the system color
// attr.SetColorKey(System.Drawing.Color.DeepPink, System.Drawing.Color.DeepPink);
// Draw the image using the image attributes.
System.Drawing.Rectangle rDest = new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height);
g.DrawImage(bmp, rDest, 0, 0, bmp.Width, bmp.Height, System.Drawing.GraphicsUnit.Pixel, attr);
}
cs_Willi
Messages postés2375Date d'inscriptionjeudi 12 juillet 2001StatutModérateurDernière intervention15 décembre 201823 20 oct. 2008 à 19:08
Tout dépend des couleurs de ton png. Je dirais 24bits si celui-ci est complexe. Si tu le crées transparent pas de soucis.
La méthode SetColorKey doit fonctionner y a pas à se tortiller... cela fonctionne sur l'émulateur.
neo2k2
Messages postés126Date d'inscriptionjeudi 16 janvier 2003StatutMembreDernière intervention 9 novembre 20093 20 oct. 2008 à 18:21
Bon alors plein de nouvelles questions:
- System.Drawing.Image bmp = new System.Drawing.Bitmap("test.png");
correspond au dossier de base de mon application, juste? Parce qu'avec l'émulateur c'est ch...
- attr.SetColorKey(bmp.GetPixel(0, 0), bmp.GetPixel(0, 0));
ne veut rien savoir! je dois utiliser:
attr.SetColorKey(System.Drawing.Color.DeepPink, System.Drawing.Color.DeepPink);
en définissant la couleur de fond de ma picturebox équivalente à System.Drawing.Color.DeepPink
- pourquoi mon png apparaît-il blanc alors que la couleur de fond définie est System.Drawing.Color.DeepPink?
comment dois-je régler mon png: 8bits, 16bits, 24bits? dois-je le créer transparent ou au contraire avec le bord DeepPink???