J'ai pour l'école un programme à écrire qui est un acdsee simplifié
La fenetre principale se découpe en trois
- Un explorateur-like
- Un flowlayoutpanel avec des picturebox pour les miniatures
- une "grande" picturebox pour l'image en grand sur laquelle on applique quelque traitement ( passage n/b - inversion de couleurs )
Pour pouvoir enregistrer dans l'image que j'ai ouvert, j'ai utilisé un Fstream
Tout mes traitements fonctionne parfaitement bien SAUF le passage en N&B
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 FileStream Fs = new FileStream(Pb.ImageLocation, FileMode.Open); Pb.Image = Image.FromStream(Fs); Fs.Close();
Qui me retourne un "OutOfmemoryExeption" ( même sur de très petites images )
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 public System.Drawing.Image TransformationNB(PictureBox Pb) { Image Img = (Image)Pb.Image.Clone(); //Image Img = Image.FromFile(Pb.ImageLocation); System.Drawing.Imaging.ImageAttributes GrayAttributes; System.Drawing.Imaging.ColorMatrix GrayMatrix = new System.Drawing.Imaging.ColorMatrix(); GrayMatrix.Matrix00 = 1 / 3.0F; GrayMatrix.Matrix01 = 1 / 3.0F; GrayMatrix.Matrix02 = 1 / 3.0F; GrayMatrix.Matrix10 = 1 / 3.0F; GrayMatrix.Matrix11 = 1 / 3.0F; GrayMatrix.Matrix12 = 1 / 3.0F; GrayMatrix.Matrix20 = 1 / 3.0F; GrayMatrix.Matrix21 = 1 / 3.0F; GrayMatrix.Matrix22 = 1 / 3.0F; GrayAttributes = new System.Drawing.Imaging.ImageAttributes(); GrayAttributes.SetColorMatrix(GrayMatrix, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Default); System.Drawing.Bitmap FinalImg = new System.Drawing.Bitmap(Img.Width, Img.Height); System.Drawing.Graphics Graphics = System.Drawing.Graphics.FromImage(FinalImg); Graphics.DrawImage(Img, new Rectangle(0, 0, FinalImg.Width, FinalImg.Height), 0, 0, FinalImg.Width, FinalImg.Height, System.Drawing.GraphicsUnit.Pixel, GrayAttributes); return FinalImg; }
Alors que si je remplace
par
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 Image Img = (Image)Pb.Image.Clone();
Tout fonctionne parfaitement ... (sauf l'enregistrement du fichier ... Vidaaament
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 Image Img = Image.FromFile(Pb.ImageLocation);)
Si quelqu'un avait une idée de pourquoi cela ne fonctionne pas si mon img est fromstream et fonctionne parfaitement avec fromfile
Partager