Knowledge Point 1: Line tracing
The carrier of totalwidth * totalheight is divided into rectangular boxes of linecolor of singlewidth * singleheight. The boxes are dashwidth width and clearance dashspace.
/// <Summary>
/// Paint? ? Network bandwidth? Ge? Bianà? Line?
/// </Summary>
Private void setgridlines (canvas carrier, double totalwidth, double totalheight, double singlewidth, double singleheight, color linecolor, double dashwidth, double dashspace ){
// What do you want to do with it ?, Why? Required? Let's take a look at it?
Carrier. Children. Clear ();
Int sectionxnum = (INT) (totalwidth/singlewidth );
Int sectionynum = (INT) (totalheight/singleheight );
For (INT x = 1; x <= sectionxnum; X ++) {// vertical?
Line line = new line (){
X1 = x * singlewidth,
X2 = x * singlewidth,
Y1 = 0,
Y2 = totalheight,
Stroke = new solidcolorbrush (linecolor ),
Strokedasharray = new doublecollection () {dashwidth, dashspace },
};
Carrier. Children. Add (line );
}
For (INT y = 1; y <= sectionynum; y ++) {// ¨?
Line line = new line (){
X1 = 0,
X2 = totalwidth,
Y1 = y * singleheight,
Y2 = y * singleheight,
Stroke = new solidcolorbrush (linecolor ),
Strokedasharray = new doublecollection () {dashwidth, dashspace },
};
Carrier. Children. Add (line );
}
}
Knowledge Point 2: Custom double-click event
Public datetime _ lastclick = datetime. now;
Private bool _ firstclickdone =
False;
Private void mainpage_mouseleftbuttondown (Object sender, mousebuttoneventargs
E)
{
Timespan
SPAN = datetime. Now-_ lastclick;
If (span. totalmilliseconds <300 & _ firstclickdone = true)
{// The two click events do not exceed 0.3 s (of course, you can also try double-click the interval by yourself) + Click the previous one (avoid 3 clicks)
// Double-click trigger
// Double-clickCodeWrite
_ Firstclickdone = false;
}
Else
{// Click it for the first time
_ Firstclickdone = true;
_ Lastclick = datetime. now;
}
Double-click events are two very fast standalone events,
Double-click = two-click interval less than 300 microseconds + previous click
Knowledge Point 3: custom long-Click Event
Private void
Obstructionviewer_previewmousemove (Object
Sender, mouseeventargs e ){
If
(E. leftbutton = mousebuttonstate. Pressed ){
// Code}
}
Long-pressed left-click event = E. leftbutton = mousebuttonstate. pressed
It's easy to see, but it's hard to know.
Knowledge Point 4: The big picture is decomposed into small pictures of the specified size
For (INT x = 0; x
<Sectionxnum; X ++ ){
For
(INT y = 0; y <sectionynum; y ++ ){
Croppedbitmap = new
Croppedbitmap (mapsource, new int32rect (x *
(INT) sectionwidth. Value, y * (INT) sectionheight. Value, (INT) sectionwidth. value,
(INT) sectionheight. Value ));
System. Io. filestream = new
System. Io. filestream (string. Format (@ "{0}/1_11__000022.16.jpg ",
Outputsection. selectedpath, x, y), system. Io. filemode. Create );
Required bitmapencoder encoder = new
Jpegbitmapencoder ();
Encoder. frames. Add (bitmapframe. Create (croppedbitmap ));
Encoder. Save (filestream );
Filestream. Close ();
}
}
- Obtain the bitmapsource of the specified size from mapsource;
- Create an event stream, and set the stream location to the saved address;
- JPG transcoding and conversion;
- Save
I will not go into details. Let's look at the code and simply follow this process.