Tourner une image

JohnBug Messages postés 7 Date d'inscription dimanche 18 décembre 2005 Statut Membre Dernière intervention 19 juillet 2011 - 19 juil. 2011 à 18:40
BunoCS Messages postés 15475 Date d'inscription lundi 11 juillet 2005 Statut Modérateur Dernière intervention 23 avril 2024 - 20 juil. 2011 à 09:45
Bonjour à tous,

je suis nouveau à C# et completement ignorant en ce qui a trait aux images.
je besoin de charger un dessin en format .wmf de le tourner de 90 degrés et de le sauvergarder dans un nouveau ficiher .wmf qui sera imprimer sur une imprimante à transfert thermique. le dessin ne contient que des lignes noires sur fond blanc.
j'ai trouver sur le web un fonction pour tourner l'image et ça marche. Le problème est que l'arrière plan du dessin semble changer au moment de la sauvegarde. Sur l'étiqutte il n'y a qu'un carré noir.

Grand merci

       

            Bitmap PicBmp = new Bitmap("C:\\__CsharpProjects\\PicRotate\\Test\\06065E1E.wmf");
            Bitmap RotPic = rotateImage(PicBmp, 90);
            RotPic.Save("C:\\__CsharpProjects\\PicRotate\\Test\\06065E1E_90.bmp",ImageFormat.Wmf);

 private Bitmap rotateImage(Bitmap b, float angle)
        {
            //create a new empty bitmap to hold rotated image
            Bitmap returnBitmap = new Bitmap(b.Width, b.Height);
            //make a graphics object from the empty bitmap
            Graphics g = Graphics.FromImage(returnBitmap);
            //move rotation point to center of image
            g.TranslateTransform((float)b.Width / 2, (float)b.Height / 2);
            //rotate
            g.RotateTransform(angle);
            //move image back
            g.TranslateTransform(-(float)b.Width / 2, -(float)b.Height / 2);
            //draw passed in image onto graphics object
            g.DrawImage(b, new Point(0, 0));
            return returnBitmap;
        }


JohnBug

1 réponse

BunoCS Messages postés 15475 Date d'inscription lundi 11 juillet 2005 Statut Modérateur Dernière intervention 23 avril 2024 103
20 juil. 2011 à 09:45
Hello,
2 questions:
- est-ce que ton image de départ à un fond transparent?
- tu sauvegardes en BMP avec le format WMF?


@+
Buno
----------------------------------------
L'urgent est fait, l'impossible est en cours. Pour les miracles, prévoir un délai...
0
Rejoignez-nous