GDI+ 图像剪切
摘要:可以利用如下函数来进行图像的剪切 // // 摘要: // 在指定位置并且按指定大小绘制指定的 System.Drawing.Image 的指定部分。 // // 参数: // image: // 要绘制的 System.Drawing.Image。 // // destRect: // System.Drawing.RectangleF 结构,它指定所绘制图像的位置和大小。将图像进行缩放以适合该矩形。 // // srcRect: // System.Drawing.RectangleF 结构,它指定 image 对象中要绘制的部分。 // // srcUnit: // System.Dra
阅读全文
posted @
2011-08-04 23:00
wtq
阅读(1264)
推荐(0) 编辑
GDI+ 调整图像的大小
摘要:原理:可通过绘图表面的属性InterploationMode来设置图像的质量。该值是个枚举类型。 简介:在设置图像质量时,若设置为高质量,则图像在屏幕显示的大小不变。但分辨率增大了,原有的像素值变小了,为了使图像能够以原来的大小显示在 屏幕上,故GDI+采用插补的过程重新绘制图像。从而达到图片质量提高的效果。如图,左边的图片的质量比较差,右边的质量比较高。 代码:View Code 1//通过改变图像的分辨率来改变图像显示在屏幕上的大小。2privatevoidForm1_Paint(objectsender,PaintEventArgse)3{4varg=e.Graphics;5Bitma.
阅读全文
posted @
2011-08-04 22:04
wtq
阅读(1476)
推荐(0) 编辑
GDI+ 设置不同的分辨率来显示不同大小的图片
摘要:通过改变内存图像的分辨率来改变图像在屏幕的大小。原理是:屏幕的大小/图像(内存的图像)的大小= 屏幕的分辨率/图像(内存的图像)的分辨率。 注意:当图像的分辨率率变大时,图像本身的像素点的大小并没有改变。 比如图像的大小为1000*1000,分辨率为300,则图像的物理尺寸是 1000/300, 当图像的分辨率变为600时,则图像的物理尺寸是1000\600。变小 了, 根据上面的计算公式:屏幕的分辨率不变,图像的分辨率变大,图像的大小变小,则屏幕的大小变得更小。所以整张图片都变小了。 可以这样...
阅读全文
posted @
2011-08-04 21:25
wtq
阅读(3468)
推荐(0) 编辑
GDI+ 图像填充屏幕或用户控件
摘要:这里通过DrawImage的另一个构造函数来填充窗体。如图;代码如下:View Code 1privatevoidForm1_Paint(objectsender,PaintEventArgse)2{3varg=e.Graphics;4Bitmapbm=newBitmap("rama.jpg");5this.Width=600;6this.Height=200;7g.DrawImage(bm,this.ClientRectangle);89Console.WriteLine("displayresolution:DPix{0},DpiY{1}",g.Dp
阅读全文
posted @
2011-08-04 20:45
wtq
阅读(416)
推荐(0) 编辑
GDI+ 通过图像的分辨率,大小,屏幕的分辨率,来计算图像的大小。
摘要:先上图,该图示一只小狗。可以有这么的一个算式:内存图像的大小/屏幕的大小 = 内存的分辨率/屏幕的分辨率代码如下:View Code 1privatevoidForm1_Paint(objectsender,PaintEventArgse)2{3varg=e.Graphics;4Bitmapbm=newBitmap("rama.jpg");5g.DrawImage(bm,0,0);67Console.WriteLine("displayresolution:DPix{0},DpiY{1}",g.DpiX,g.DpiY);8Console.WriteLin
阅读全文
posted @
2011-08-04 20:39
wtq
阅读(514)
推荐(0) 编辑
GDI+ 获取本地电脑的图片编码器
摘要:如图是我的电脑的图片编码器 代码如下:View Code 1//imagecoder的类型2privatevoidForm1_Paint(objectsender,PaintEventArgse)3{4ImageCodecInfo[]availableImageCodecInfo;5availableImageCodecInfo=ImageCodecInfo.GetImageEncoders();6foreach(variteminavailableImageCodecInfo)7{8Console.WriteLine(item.CodecName);9Console.WriteLine(it
阅读全文
posted @
2011-08-03 16:27
wtq
阅读(548)
推荐(0) 编辑
GDI+ 如何查看电脑已经安装了多少字体。
摘要:使用InstalledFontCollection来获得电脑已经安装的字体有哪些。如图;代码如下:View Code 1//查看电脑有多少字体2privatevoidForm1_Paint(objectsender,PaintEventArgse)3{4FontFamily[]fontfamilys;5InstalledFontCollectioninstalledFontCollection=newInstalledFontCollection();6fontfamilys=installedFontCollection.Families;7foreach(variteminfontfami
阅读全文
posted @
2011-08-02 22:51
wtq
阅读(878)
推荐(0) 编辑
GDI+ 使用笔刷绘制字体
摘要:以下将采用十字架来绘制字体。如图:1.思路,先创建图案笔刷,然后再绘制图形。代码如下: View Code 1privatevoidForm1_Paint(objectsender,PaintEventArgse)2{3Graphicsg=e.Graphics;45Fontf=newFont("Aries",60,FontStyle.Bold);6HatchBrushhb=newHatchBrush(HatchStyle.Cross,Color.Blue,Color.Gray);7g.DrawString("我叫王王王",f,hb,0f,20f);8g.
阅读全文
posted @
2011-08-02 22:25
wtq
阅读(575)
推荐(0) 编辑
GDI+ 绘制自定义制表位位数的文本。
摘要:先上图;2,使用StringFormat中的SetTabStops来设置制表位所占的空间StringFormat sf = new StringFormat(); sf.StTabStops(5f, ff);代码如下:View Code privatevoidForm1_Paint(objectsender,PaintEventArgse){Graphicsg=e.Graphics;Fontf=newFont("Aries",15,FontStyle.Italic);Fontfb=newFont(f,FontStyle.Bold);strings1="\twtq\
阅读全文
posted @
2011-08-02 21:01
wtq
阅读(566)
推荐(0) 编辑
GDI+ 设置文本对齐方式
摘要:可通过以下语句来设置文本的对齐方式:StringFormat sF = new StringFormat()sF.Alignment = StringAlignment.Far;sF.LineAlignment = StringAlignment.Far;代码:、View Code privatevoidForm1_Paint(objectsender,PaintEventArgse){Graphicsg=e.Graphics;Fontf=newFont("Aris",15,FontStyle.Italic);strings="thisismyname"
阅读全文
posted @
2011-08-02 13:01
wtq
阅读(665)
推荐(0) 编辑
GDI+绘制竖向文本
摘要:可通过StringFormat sF = new StringFormat(StringFormatFlags.DirectionVertical);以及使用 g.DrawString(s, f, Brushes.Black, rf,sF);来绘制竖向文本 View Code privatevoidForm1_Paint(objectsender,PaintEventArgse){Graphicsg=e.Graphics;Fontf=newFont("Aris",15,FontStyle.Italic);strings="thisismyname,andwhat&
阅读全文
posted @
2011-08-02 13:00
wtq
阅读(825)
推荐(0) 编辑
GDI+ 绘制多行文本,自动换行。
摘要:1,主要利用MessageString()这个函数来实现自动换行。截图如下:代码如下:View Code //绘制有边框的字体,并自动换行privatevoidForm1_Paint(objectsender,PaintEventArgse){Graphicsg=e.Graphics;Fontf=newFont("Aris",15,FontStyle.Italic|FontStyle.Strikeout);strings="thisismyname,andwhataboutyou,oknoproblems,everyisok,somethingisgoods,pr
阅读全文
posted @
2011-08-02 08:25
wtq
阅读(3291)
推荐(1) 编辑
GDI+ 绘制多行文本
摘要:绘制多行文本,如图:思路主要设置drawstring的第二个参数的高度,这样就ok了。代码如下;View Code //privatevoidForm1_Paint(objectsender,PaintEventArgse)//{//Graphicsg=e.Graphics;//FontFamilyff=newFontFamily(GenericFontFamilies.Serif);//Fontf=newFont(ff,12,FontStyle.Italic|FontStyle.Bold|FontStyle.Strikeout|FontStyle.Underline);//stringst.
阅读全文
posted @
2011-07-30 01:21
wtq
阅读(814)
推荐(0) 编辑
GDI+ 绘制有边框的字体
摘要:绘制有边框的字体,如图思路,通过stringMessure来获取字体的长度。如下:View Code privatevoidForm1_Paint(objectsender,PaintEventArgse){Graphicsg=e.Graphics;FontFamilyff=newFontFamily(GenericFontFamilies.Serif);Fontf=newFont(ff,12,FontStyle.Italic);stringstr="Height"+f.Height;//不添加而外的高度SizeFsf=g.MeasureString(str,f,int.M
阅读全文
posted @
2011-07-30 00:59
wtq
阅读(1375)
推荐(0) 编辑
GDI+ 使用窗体默认字体
摘要:下面将演示如何使用窗体的默认字体。 privatevoidForm1_Paint(objectsender,PaintEventArgse){FontFamilyff=newFontFamily(GenericFontFamilies.SansSerif);Fontf=newFont(ff,13,GraphicsUnit.Millimeter);Fontf1=newFont(ff,13,GraphicsUnit.Point);using(Fontf2=newFont(ff,23,FontStyle.Strikeout)){Graphicsg=e.Graphics;g.DrawString(&q
阅读全文
posted @
2011-07-29 23:58
wtq
阅读(476)
推荐(0) 编辑
GDI+ 钢笔和笔刷同时使用
摘要:可通过钢笔和笔刷混合 使用绘制出有边框的填充图案,如图:代码如下:View Code privatevoidForm1_Paint(objectsender,PaintEventArgse){Graphicsg=e.Graphics;HatchBrushhb=newHatchBrush(HatchStyle.NarrowHorizontal,Color.Blue,Color.White);LinearGradientBrushlgb=newLinearGradientBrush(newPoint(2,2),newPoint(19,2),Color.Blue,Color.Brown);Penh.
阅读全文
posted @
2011-07-29 21:52
wtq
阅读(404)
推荐(1) 编辑
GDI+ 通过笔刷创建钢笔并绘制图案
摘要:先上图:提示:可通过笔刷来创建钢笔并绘制图形,以上是通过HatchBrush 来创建钢笔的。View Code privatevoidForm1_Paint(objectsender,PaintEventArgse){Graphicsg=e.Graphics;HatchBrushhb=newHatchBrush(HatchStyle.NarrowHorizontal,Color.Red,Color.White);Penhp=newPen(hb,8);g.DrawRectangle(hp,12,12,200,200);hb.Dispose();}还可以通过LinearGridentBrush来.
阅读全文
posted @
2011-07-29 21:40
wtq
阅读(473)
推荐(0) 编辑
GGI+ 通过HatchBrush画刷来填充区域。
摘要:先上图:通过hatchbrush根据图案来填充,可通过HatchStyle枚举来设置图案。 代码如下:View Code privatevoidForm1_Paint(objectsender,PaintEventArgse){Graphicsg=e.Graphics;HatchBrushhb=newHatchBrush(HatchStyle.OutlinedDiamond,Color.Red,Color.White);g.FillRectangle(hb,ClientRectangle);hb.Dispose();}
阅读全文
posted @
2011-07-29 20:51
wtq
阅读(345)
推荐(0) 编辑
GDI+ 绘制路径渐变图形
摘要:通过路径渐变画刷来绘制图片代码如下:View Code privatevoidForm1_Paint(objectsender,PaintEventArgse){Graphicsg=e.Graphics;GraphicsPathgp=newGraphicsPath();Point[]p=newPoint[]{newPoint(10,10),newPoint(100,30),newPoint(50,100)};gp.AddLines(p);PathGradientBrushpgb=newPathGradientBrush(gp);pgb.CenterColor=Color.White;pgb..
阅读全文
posted @
2011-07-29 20:40
wtq
阅读(1564)
推荐(0) 编辑
GDI+ Pen Brush
摘要:以下介绍pen的一些属性:1.画笔绘制方式Pen.Alignment 属性设置当钢笔的宽度超过1像素的时候,该如何绘制有Center,Inset ,Outset,Left,right。View Code Pena=newPen(Color.Tomato,20);a.Alignment=PenAlignment.Outset;g.DrawRectangle(a,50,50,100,100);2.定制短划线:View Code Pena=newPen(Color.Tomato,1);a.Alignment=PenAlignment.Outset;float[]f={15,5,10,2,30,10.
阅读全文
posted @
2011-07-28 15:40
wtq
阅读(491)
推荐(0) 编辑