知識點1:描線
吧totalWidth*totalHeight的carrier分成singleWidth*singleHeight的lineColor顏色的矩形框,框為dashWidth寬,間隙dashSpace
/// <summary>
/// 繪?制?網ª?格?邊À?線?
/// </summary>
private void SetGridLines(Canvas carrier, double totalWidth, double totalHeight, double singleWidth, double singleHeight,Color lineColor, double dashWidth, double dashSpace) {
//欲與之?,ê?必À?先¨¨舍¦¨¢之?
carrier.Children.Clear();
int sectionXNum = (int)(totalWidth / singleWidth);
int sectionYNum = (int)(totalHeight / singleHeight);
for (int x = 1; x <= sectionXNum; x++) {//豎º¨²線?
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);
}
}
知識點2:自訂雙擊事件
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)
{ //兩次點擊事件不超過0.3s(當然你也可以自己嘗試一般雙擊間隔時間)+前一次是單擊(避免3擊)
//雙擊觸發
//雙擊代碼請在這裡編寫
_firstClickDone = false;
}
else
{ //第一次點擊
_firstClickDone = true;
_lastClick = DateTime.Now;
}
所謂雙擊事件就是很快的兩次單機,
雙擊=兩次單擊時間間隔少於300微秒+前一次是單擊
知識點3:自訂長按左鍵事件
private void
ObstructionViewer_PreviewMouseMove(object
sender, MouseEventArgs e) {
if
(e.LeftButton == MouseButtonState.Pressed) {
//code }
}
長按左鍵事件= e.LeftButton == MouseButtonState.Pressed
簡單吧,看了感覺很簡單啊,但是不知道就很難嘍。
知識點4:大圖分解為指定尺寸的小圖
for (int x = 0; x
< sectionXNum; x++) {
for
(int y = 0; y < sectionYNum; y++) {
CroppedBitmap croppedBitmap = new
CroppedBitmap(mapSource, new Int32Rect(x *
(int)SectionWidth.Value, y * (int)SectionHeight.Value, (int)SectionWidth.Value,
(int)SectionHeight.Value));
System.IO.FileStream fileStream = new
System.IO.FileStream(string.Format(@"{0}/{1}_{2}.jpg",
outputSection.SelectedPath, x, y), System.IO.FileMode.Create);
JpegBitmapEncoder encoder = new
JpegBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(croppedBitmap));
encoder.Save(fileStream);
fileStream.Close();
}
}
- 從mapSource得到指定位置指定大小的BitmapSource源;
- 建立個事件流,流位置即儲存地址設定好;
- Jpg轉碼轉換;
- 儲存
就不詳細說了,自己看代碼吧,就按這個流程來就行了。