Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    Immagini in scala di grigi

    Ciao a tutti.
    E' possibile trasformare una immagine in scala di grigi, magari con la cara System.Drawing.Imaging?

    Grazie...

  2. #2
    Utente di HTML.it L'avatar di nicki
    Registrato dal
    Dec 2000
    Messaggi
    139
    Io faccio così

    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.
    Ciao, nic.

  3. #3
    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

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.