|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
无论谁倒了对双方阵营的粉丝们也是有害无益。制造一个复杂的WPF图片扫瞄器
这里将完成以下几个功效:
1.对指定文件夹下一切JPG文件举行预览
2.对选定片举行扭转
3.对选定片举行灰度处置
4.对选定片举行裁切处置
5.无穷制的恢复功效
6.相似到场购物车的功效
以上去看看实在现历程。
1.创建一个ImageFile类,用来读取像文件:
//ImageFile.cs
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Windows.Media.Imaging;
usingSystem.Text;
namespacePhotoDemo
{
publicclassImageFile
{
privateString_path;
publicStringPath{get{return_path;}}
privateUri_uri;
publicUriUri{get{return_uri;}}
privateBitmapFrame_image;
publicBitmapFrameImage{get{return_image;}}
publicImageFile(stringpath)
{
_path=path;
_uri=newUri(_path);
_image=BitmapFrame.Create(_uri);
}
publicoverridestringToString()
{
returnPath;
}
}
}
2.创建一个像列表的类,用于获得指定目次下的一切jpg像文件:
//PhotoList.cs
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Collections.ObjectModel;
usingSystem.IO;
usingSystem.Text;
namespacePhotoDemo
{
publicclassPhotoList:ObservableCollection<ImageFile>
{
DirectoryInfo_directory;
publicDirectoryInfoDirectory
{
set
{
_directory=value;
Update();
}
get{return_directory;}
}
publicstringPath
{
set
{
_directory=newDirectoryInfo(value);
Update();
}
get{return_directory.FullName;}
}
publicPhotoList(){}
publicPhotoList(DirectoryInfodirectory)
{
_directory=directory;
Update();
}
publicPhotoList(stringpath):this(newDirectoryInfo(path)){}
privatevoidUpdate()
{
foreach(FileInfofin_directory.GetFiles("*.jpg"))
{
Add(newImageFile(f.FullName));
}
}
}
}
这里有两个大众属性:Directory和Path,用来猎取或设置像目次信息和路径,另有一个Update()公有办法,当文件路径变更时,更新最新的像文件列表数据。
3.创建前期处置的类。
因为前期加工均触及“印”,以是就创建一个名为“印范例”(PrintType)的类:
//PrintType.cs
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Text;
namespacePhotoDemo
{
publicclassPrintType
{
privatestring_description;
publicstringDescription{get{return_description;}}
privatedouble_cost;
publicdoubleCost{get{return_cost;}}
publicPrintType(stringdescription,doublecost)
{
_description=description;
_cost=cost;
}
publicoverridestringToString()
{
return_description;
}
}
}
这里有两个只读属性:形貌Description和用度Cost,还对ToString()办法举行了重载。
4.PrintTypeList类,是PrintType列表的汇合。</P></strong>//PrintTypeList.cs
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Collections.ObjectModel;
usingSystem.Text;
namespacePhotoDemo
{
publicclassPrintTypeList:ObservableCollection<PrintType>
{
publicPrintTypeList()
{
Add(newPrintType("4x6Print",0.15));
Add(newPrintType("GreetingCard",1.49));
Add(newPrintType("T-Shirt",14.99));
}
}
}
5.创建一个PrintBase的类:
//PrintBase.cs
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Windows.Media.Imaging;
usingSystem.Text;
namespacePhotoDemo
{
publicclassPrintBase:INotifyPropertyChanged
{
#regionpublicproperty
privateBitmapSource_photo;
publicBitmapSourcePhoto
{
set{_photo=value;OnPropertyChanged("Photo");}
get{return_photo;}
}
privatePrintType_PrintType;
publicPrintTypePrintType
{
set{_PrintType=value;OnPropertyChanged("PrintType");}
get{return_PrintType;}
}
privateint_quantity;
publicintQuantity
{
set{_quantity=value;OnPropertyChanged("Quantity");}
get{return_quantity;}
}
#endregionpublicproperty
publicPrintBase(BitmapSourcephoto,PrintTypeprinttype,intquantity)
{
Photo=photo;
PrintType=printtype;
Quantity=quantity;
}
publicPrintBase(BitmapSourcephoto,stringdescription,doublecost)
{
Photo=photo;
PrintType=newPrintType(description,cost);
Quantity=0;
}
publiceventPropertyChangedEventHandlerPropertyChanged;
privatevoidOnPropertyChanged(Stringinfo)
{
if(PropertyChanged!=null)
PropertyChanged(this,newPropertyChangedEventArgs(info));
}
publicoverridestringToString()
{
returnPrintType.ToString();
}
}
}
这里有三个可读写属性:Photo,PrintType和Quantity(暗示片的数目),还设置了一个PropertyChanged托付,用于当属性变动时做响应的事务处置。
6.承继自PrintBase的三个类:Print,GreetingCard,TShirt,分离用来打印,制成贺卡及制造T恤衫。
//Print.cs
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Windows.Media.Imaging;
usingSystem.Text;
namespacePhotoDemo
{
publicclassPrint:PrintBase
{
publicPrint(BitmapSourcephoto):base(photo,"4x6Print",0.15){}
}
}
//TShirt.cs
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Windows.Media.Imaging;
usingSystem.Text;
namespacePhotoDemo
{
publicclassTShirt:PrintBase
{
publicTShirt(BitmapSourcephoto):base(photo,"T-Shirt",14.99){}
}
}
//GreetingCard.cs
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Windows.Media.Imaging;
usingSystem.Text;
namespacePhotoDemo
{
publicclassGreetingCard:PrintBase
{
publicGreetingCard(BitmapSourcephoto):base(photo,"GreetingCard",1.49){}
}
}
7."印"的汇合:PrintList
//PrintList.cs
usingSystem;
usingSystem.Collections.ObjectModel;
namespacePhotoDemo
{
publicclassPrintList:ObservableCollection<PrintBase>{}
}
你可以先看看这篇文章(软微学院生涯-三朝元老经验谈),打不开再跟我说。(我的意思是想让她自己先稍微了解一下到底现在各个方向学的工具以及以后要做的工具大概是什么,因为喜欢做什么样的事其实自己最清楚的) |
|