Ciao a tutti.
E' possibile trasformare una immagine in scala di grigi, magari con la cara System.Drawing.Imaging?
![]()
Grazie...
Ciao a tutti.
E' possibile trasformare una immagine in scala di grigi, magari con la cara System.Drawing.Imaging?
![]()
Grazie...
Io faccio così
ciao.codice:private System.Drawing.Image GrayScaleImage(System.Drawing.Image img){ int Height = img.Height,Width = img.Width; System.Drawing.Bitmap imgBMP = new System.Drawing.Bitmap(img); Color _color; for (int i=0;i<Width;i++) for (int j=0;j<Height;j++){ _color = imgBMP.GetPixel(i,j); int _gray = (_color.R + _color.G + _color.B) / 3; imgBMP.SetPixel(i,j,Color.FromArgb(_gray,_gray,_gray)); } return (System.Drawing.Image)imgBMP; }
Ciao, nic.
grazie mille!
ho trovato anche questa:
codice:Public Shared Sub MakeImageGrayscale(ByVal bmp As Bitmap) Dim cMatrix As New ColorMatrix(New Single()() _ {New Single() {0.299, 0.299, 0.299, 0, 0}, _ New Single() {0.587, 0.587, 0.587, 0, 0}, _ New Single() {0.114, 0.114, 0.114, 0, 0}, _ New Single() {0, 0, 0, 1, 0}, _ New Single() {0, 0, 0, 0, 1}}) Dim imageAttrib As New ImageAttributes imageAttrib.SetColorMatrix(cMatrix) Dim gr As Graphics = Graphics.FromImage(bmp) 'Apply the grayscale image attribute gr.DrawImage(bmp, New Rectangle(0, 0, bmp.Width, bmp.Height), _ 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, imageAttrib) gr.Dispose() End Sub![]()