Show image effect in fade display image The main use of the ImageAttributes class SetColorMatrix method to set the color adjustment matrix to achieve the effect of fading. The ImageAttributes object maintains multiple color adjustment settings, including color-adjustment matrices, grayscale-adjustment matrices, grayscale correction values, color-map tables, and color thresholds. Color can be corrected, darkened, lightened, and removed during rendering. The fade effect code is as follows:
private void Button1_Click (object sender, EventArgs e)
{
Fade in image
Try
{
Graphics g = this.panel1.CreateGraphics ();
G.clear (Color.gray);
int width = mybitmap.width;
int height = mybitmap.height;
ImageAttributes attributes = new ImageAttributes ();
ColorMatrix matrix = new ColorMatrix ();
To create a fade color matrix
Matrix. Matrix00 = (float) 0.0;
Matrix. Matrix01 = (float) 0.0;
Matrix. Matrix02 = (float) 0.0;
Matrix. Matrix03 = (float) 0.0;
Matrix. Matrix04 = (float) 0.0;
Matrix. Matrix10 = (float) 0.0;
Matrix. Matrix11 = (float) 0.0;
Matrix. Matrix12 = (float) 0.0;
Matrix. Matrix13 = (float) 0.0;
Matrix. Matrix14 = (float) 0.0;
Matrix. Matrix20 = (float) 0.0;
Matrix. Matrix21 = (float) 0.0;
Matrix. Matrix22 = (float) 0.0;
Matrix. Matrix23 = (float) 0.0;
Matrix. Matrix24 = (float) 0.0;
Matrix. Matrix30 = (float) 0.0;
Matrix. Matrix31 = (float) 0.0;
Matrix. Matrix32 = (float) 0.0;
Matrix. Matrix33 = (float) 0.0;
Matrix. Matrix34 = (float) 0.0;
Matrix. Matrix40 = (float) 0.0;
Matrix. Matrix41 = (float) 0.0;
Matrix. Matrix42 = (float) 0.0;
Matrix. Matrix43 = (float) 0.0;
Matrix. Matrix44 = (float) 0.0;
Matrix. Matrix33 = (float) 1.0;
Matrix. Matrix44 = (float) 1.0;
Modify the values on the main diagonal of the color transformation matrix from 0 to 1
Increases the saturation of three base colors
Single count = (float) 0.0;
while (Count < 1.0)
{
Matrix. Matrix00 = count;
Matrix. Matrix11 = count;
Matrix. Matrix22 = count;
Matrix. Matrix33 = count;
Attributes. SetColorMatrix (Matrix, Colormatrixflag.default, Coloradjusttype.bitmap);
G.drawimage (Mybitmap, New Rectangle (0, 0, width, height), 0, 0, width, height, graphicsunit.pixel, attributes);
System.Threading.Thread.Sleep (200);
Count = (float) (count + 0.02);
}
}
catch (Exception ex)
{
MessageBox.Show (ex. message, "information hint");
}
}