17-10-12, 06:07 PM
كاتب الموضوع : Boutemine Oualid
السلام عليكم و رحمة الله و بركاتهفيبي .نت
كود :
Public Function InvertColors(ByVal Img As System.Drawing.Image) As System.Drawing.Image
Dim InvertAttributes As System.Drawing.Imaging.ImageAttributes
Dim InvertMatrix As New System.Drawing.Imaging.ColorMatrix
InvertMatrix.Matrix00 = -1
InvertMatrix.Matrix11 = -1
InvertMatrix.Matrix22 = -1
InvertMatrix.Matrix33 = 1
InvertMatrix.Matrix40 = 1
InvertMatrix.Matrix41 = 1
InvertMatrix.Matrix42 = 1
InvertMatrix.Matrix44 = 1
InvertAttributes = New System.Drawing.Imaging.ImageAttributes()
InvertAttributes.SetColorMatrix(InvertMatrix, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Default)
Dim FinalImg As New System.Drawing.Bitmap(Img.Width, Img.Height)
Dim Graphics As System.Drawing.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, InvertAttributes)
Return FinalImg
End Function
كود :
public System.Drawing.Image InvertColors(System.Drawing.Image Img)
{
System.Drawing.Imaging.ImageAttributes InvertAttributes;
System.Drawing.Imaging.ColorMatrix InvertMatrix = new System.Drawing.Imaging.ColorMatrix();
InvertMatrix.Matrix00 = -1;
InvertMatrix.Matrix11 = -1;
InvertMatrix.Matrix22 = -1;
InvertMatrix.Matrix33 = 1;
InvertMatrix.Matrix40 = 1;
InvertMatrix.Matrix41 = 1;
InvertMatrix.Matrix42 = 1;
InvertMatrix.Matrix44 = 1;
InvertAttributes = new System.Drawing.Imaging.ImageAttributes();
InvertAttributes.SetColorMatrix(InvertMatrix, 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, InvertAttributes);
return FinalImg;
}