It took two nights to generate a grayscale image and used the ColorMatrix class. We wanted to set a 5*5 parameter matrix. I didn't understand the matrix copied on MSDN, it takes a lot of time to understand errors in two places when dragging, as recorded here:
1. Drag in. The e. Data. GetData (DataFormats. FileDrop) parameter is initially considered as DataFormats. Bitmap, and the returned Data is considered as Bitmap Data. The correct code is as follows:
Private void flowLayoutPanel _ Original Image _ DragDrop (object sender, DragEventArgs e)
{
If (e. Data. GetDataPresent (DataFormats. FileDrop ))
{
String [] fileList = (string []) (e. Data. GetData (DataFormats. Bitmap ));
Foreach (string fileName in fileList)
{
Image image = Image. FromFile (fileName );
PictureBox pictureBox = new PictureBox ();
PictureBox. Size = new Size (this. PicWidth, this. PicHeight );
PictureBox. SizeMode = PictureBoxSizeMode. StretchImage;
PictureBox. Image = image;
FileInfo info = new FileInfo (fileName );
PictureBox. Tag = info. Name;
This. flowLayoutPanel1.Controls. Add (pictureBox );
}
}
}
2. Drag-out: Put the stored data into a DataObject and set the DataFormats. bitmap format to indicate the data type. In fact, it is also wrong. In fact, the data to be saved is saved as a file, and the path of the file is used as the data, and DataFormats. FileDrop is used as the parameter, so that the drag effect can be completed. The key is DoDragDrop (new DataObject (DataFormats. FileDrop, files ),
DragDropEffects. Move/* | DragDropEffects. Link */); note that files is a string [] array. It takes a long time to find the cause when a string is always used. The complete code is as follows:
Void pictureBox_MouseMove (object sender, MouseEventArgs e)
{
PictureBox pictureBox = sender as PictureBox;
If (e. Button & MouseButtons. Left) = MouseButtons. Left)
{
If (dragBoxFromMouseDown! = Rectangle. Empty &&
! DragBoxFromMouseDown. Contains (e. X, e. Y ))
{
DataObject dataObject = new DataObject ();
String imageName = pictureBox. tag. toString (). substring (0, pictureBox. tag. toString (). lastIndexOf (". ") +" _ gray "+ pictureBox. tag. toString (). substring (pictureBox. tag. toString (). lastIndexOf (". "));
String fileName = this. CreateTemporaryFileName (imageName, pictureBox. Image );
String [] files = new string [1] {fileName };
DoDragDrop (new DataObject (DataFormats. FileDrop, files), DragDropEffects. Move/* | DragDropEffects. Link */);
}
}
}
Paste a picture:
Code download