codice:
public static void ImgConvertNegativeMatrix(System.Drawing.Bitmap bitmap)
{
System.Drawing.Rectangle bounds = new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height);
//Dim matrix As New System.Drawing.Imaging.ColorMatrix()
//matrix(0, 0) = -1
//matrix(1, 1) = -1
//matrix(2, 2) = -1
float[][] values = {
new float[] {-1, 0, 0, 0, 0},
new float[] {0, -1, 0, 0, 0},
new float[] {0, 0, -1, 0, 0},
new float[] {0, 0, 0, 1, 0},
new float[] {0, 0, 0, 0, 1}};
//usa la matrice per inizializzare un oggetto colorMatrix
System.Drawing.Imaging.ColorMatrix matrix = new System.Drawing.Imaging.ColorMatrix(values);
System.Drawing.Imaging.ImageAttributes attributes = new System.Drawing.Imaging.ImageAttributes();
attributes.SetColorMatrix(matrix);
System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap);
graphics.DrawImage(bitmap, bounds, 0, 0, bitmap.Width, bitmap.Height, System.Drawing.GraphicsUnit.Pixel, attributes);
graphics.Dispose();
}
uso questo codice per rendere negativa una immagine. L'unica cosa che combino è però trasformare l'immagine in un rettangolo completamente nero :master:
Dove sbaglio?