資源簡(jiǎn)介
自己用c#寫的鼠標(biāo)畫框矩形裁剪圖片工具,含源碼及工程文件,可編譯運(yùn)行,在win7的64為系統(tǒng)下做過(guò)測(cè)試,親測(cè)可用,其他的系統(tǒng)版本未試過(guò)。

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Windows.Forms;
using?System.Drawing.Drawing2D;
using?System.Drawing.Imaging;
using?ImageClassLib;
namespace?ImageShear
{
????public?partial?class?Form4?:?Form
????{
????????public?Form4()
????????{
????????????InitializeComponent();
????????}
????????#region??矩形裁剪
????????int?x1;?????//鼠標(biāo)按下時(shí)橫坐標(biāo)
????????int?y1;?????//鼠標(biāo)按下時(shí)縱坐標(biāo)
????????int?width;??//所打開(kāi)的圖像的寬
????????int?heigth;?//所打開(kāi)的圖像的高
????????bool?HeadImageBool?=?false;????//?此布爾變量用來(lái)判斷pictureBox1控件是否有圖片
????????Point?p1;???//定義鼠標(biāo)按下時(shí)的坐標(biāo)點(diǎn)
????????Point?p2;???//定義移動(dòng)鼠標(biāo)時(shí)的坐標(biāo)點(diǎn)
????????Point?p3;???//定義松開(kāi)鼠標(biāo)時(shí)的坐標(biāo)點(diǎn)
????????public?string?strHeadImagePath;?//打開(kāi)圖片的路徑
????????Bitmap?Bi;??//定義位圖對(duì)像
????????ImageCut1?IC1;??//定義所畫矩形的圖像對(duì)像
????????#region?點(diǎn)擊打開(kāi)圖像
????????private?void?button10_Click(object?sender?EventArgs?e)
????????{
????????????//設(shè)置讀取圖片類型
????????????openFileDialog1.Filter?=?“*.gif|*.jpg|*.JPEG|*.JPEG|*.bmp|*.bmp“;?????????
????????????if?(openFileDialog1.ShowDialog()?==?DialogResult.OK)
????????????{
????????????????try
????????????????{
????????????????????strHeadImagePath?=?openFileDialog1.FileName;
????????????????????//使用打開(kāi)的圖片路徑創(chuàng)建位圖對(duì)像
????????????????????Bi?=?new?Bitmap(strHeadImagePath);
????????????????????//實(shí)例化ImageCut類,四個(gè)參數(shù)據(jù)分別表示為:x、y、width、heigth,(40、112)表示pictureBox1的Lcation的坐標(biāo),(120、144)表示pictureBox1控件的寬度和高度??
????????????????????ImageCut?IC?=?new?ImageCut(40?112?this.pictureBox4.Width?this.pictureBox4.Height);
????????????????????//(120、144)表示pictureBox1控件的寬度和高度
????????????????????this.pictureBox4.Image?=?IC.KiCut((Bitmap)(this.GetSelectImage(this.pictureBox4.Width?this.pictureBox4.Height)));?????
????????????????}
????????????????catch?(Exception?ex)
????????????????{
????????????????????MessageBox.Show(“格式不對(duì)“);
????????????????????ex.ToString();
????????????????}
????????????}
????????????else
????????????{
????????????}
????????}
????????#endregion
????????#region?獲取圖像
????????///?
????????///?獲取指定寬度和高度的圖像即使圖片和pictureBox1控件一樣寬和高,返回值為圖片Image
????????///?
????????///?
????????///?
????????///?
????????public?Image?GetSelectImage(int?Width?int?Height)
????????{
????????????//Image?initImage?=?this.pictureBox1.Image;
????????????Image?initImage?=?Bi;
????????????//原圖寬高均小于模版,不作處理,直接保存?
????????????if?(initImage.Width?<=?Width?&&?initImage.Height?<=?Height)
????????????{
????????????????//initImage.Save(fileSaveUrl?System.Drawing.Imaging.ImageFormat.Jpeg);
????????????????return?initImage;
????????????}
????????????else
????????????{
????????????????//原始圖片的寬、高?
????????????????int?initWidth?=?initImage.Width;
????????????????int?initHeight?=?initImage.Height;
????????????????//非正方型先裁剪為正方型?
????????????????if?(initWidth?!=?in
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
????..A..H.?????71680??2018-12-04?10:30??矩形裁剪工具\(yùn)ImageShear\.vs\ImageShear\v14\.suo
?????文件??????13824??2017-08-24?13:42??矩形裁剪工具\(yùn)ImageShear\ImageShear\bin\Debug\ImageShear.exe
?????文件??????30208??2017-08-24?13:42??矩形裁剪工具\(yùn)ImageShear\ImageShear\bin\Debug\ImageShear.pdb
?????文件??????22696??2018-12-04?10:30??矩形裁剪工具\(yùn)ImageShear\ImageShear\bin\Debug\ImageShear.vshost.exe
?????文件????????490??2015-06-04?12:48??矩形裁剪工具\(yùn)ImageShear\ImageShear\bin\Debug\ImageShear.vshost.exe.manifest
?????文件??????14134??2017-08-24?13:42??矩形裁剪工具\(yùn)ImageShear\ImageShear\Form4.cs
?????文件???????4308??2017-08-23?15:58??矩形裁剪工具\(yùn)ImageShear\ImageShear\Form4.Designer.cs
?????文件???????6020??2017-08-23?15:57??矩形裁剪工具\(yùn)ImageShear\ImageShear\Form4.resx
?????文件???????2688??2012-07-16?15:21??矩形裁剪工具\(yùn)ImageShear\ImageShear\ImageCut.cs
?????文件???????3194??2017-08-24?13:42??矩形裁剪工具\(yùn)ImageShear\ImageShear\ImageCut1.cs
?????文件???????3758??2017-08-23?15:53??矩形裁剪工具\(yùn)ImageShear\ImageShear\ImageShear.csproj
?????文件????????228??2017-08-23?15:53??矩形裁剪工具\(yùn)ImageShear\ImageShear\ImageShear.csproj.user
?????文件???????5423??2017-08-23?14:57??矩形裁剪工具\(yùn)ImageShear\ImageShear\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件???????7167??2018-12-04?10:30??矩形裁剪工具\(yùn)ImageShear\ImageShear\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件???????1710??2012-07-17?08:54??矩形裁剪工具\(yùn)ImageShear\ImageShear\obj\x86\Debug\GenerateResource.read.1.tlog
?????文件???????3194??2012-07-17?08:54??矩形裁剪工具\(yùn)ImageShear\ImageShear\obj\x86\Debug\GenerateResource.write.1.tlog
?????文件???????5197??2018-12-04?10:30??矩形裁剪工具\(yùn)ImageShear\ImageShear\obj\x86\Debug\ImageShear.csproj.FileListAbsolute.txt
?????文件???????1012??2017-08-23?15:58??矩形裁剪工具\(yùn)ImageShear\ImageShear\obj\x86\Debug\ImageShear.csproj.GenerateResource.Cache
?????文件??????11633??2017-08-23?15:26??矩形裁剪工具\(yùn)ImageShear\ImageShear\obj\x86\Debug\ImageShear.csprojResolveAssemblyReference.cache
?????文件??????13824??2017-08-24?13:42??矩形裁剪工具\(yùn)ImageShear\ImageShear\obj\x86\Debug\ImageShear.exe
?????文件??????10580??2012-07-16?22:19??矩形裁剪工具\(yùn)ImageShear\ImageShear\obj\x86\Debug\ImageShear.Form1.resources
?????文件????????180??2012-07-16?22:19??矩形裁剪工具\(yùn)ImageShear\ImageShear\obj\x86\Debug\ImageShear.Form2.resources
?????文件????????180??2012-07-16?22:19??矩形裁剪工具\(yùn)ImageShear\ImageShear\obj\x86\Debug\ImageShear.Form3.resources
?????文件????????180??2017-08-23?15:58??矩形裁剪工具\(yùn)ImageShear\ImageShear\obj\x86\Debug\ImageShear.Form4.resources
?????文件????????180??2012-07-16?22:19??矩形裁剪工具\(yùn)ImageShear\ImageShear\obj\x86\Debug\ImageShear.frmScreen.resources
?????文件??????30208??2017-08-24?13:42??矩形裁剪工具\(yùn)ImageShear\ImageShear\obj\x86\Debug\ImageShear.pdb
?????文件????????180??2017-08-23?15:53??矩形裁剪工具\(yùn)ImageShear\ImageShear\obj\x86\Debug\ImageShear.Properties.Resources.resources
?????文件??????11999??2012-07-17?08:54??矩形裁剪工具\(yùn)ImageShear\ImageShear\obj\x86\Debug\ResolveAssemblyReference.cache
?????文件????????491??2012-07-16?15:10??矩形裁剪工具\(yùn)ImageShear\ImageShear\Program.cs
?????文件???????1376??2012-07-10?14:26??矩形裁剪工具\(yùn)ImageShear\ImageShear\Properties\AssemblyInfo.cs
............此處省略26個(gè)文件信息
評(píng)論
共有 條評(píng)論