WPF game excerpt-map editor (2)

Source: Internet
Author: User
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 ();

}

}

    1. Obtain the bitmapsource of the specified size from mapsource;
    2. Create an event stream, and set the stream location to the saved address;
    3. JPG transcoding and conversion;
    4. Save

I will not go into details. Let's look at the code and simply follow this process.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.