Graphics 和 Matrix 使用注意
Graphics 可以进行画图,Matrix 可以对画布内容进行变换
Fontfont=newFont("宋体",1F);//检测字符串大小SizeFsizeF=CreateGraphics().MeasureString("abc",font);//displayWidth为实际显示宽度,通过此方式将字体变大floatdisX=(float)(displayWidth/sizeF.Width);floatdisY=(float)(displayHeight/sizeF.Height);Matrixmatrix=newMatrix();//对画布内容进行放大matrix.Scale(disX,disY);//这里用在panel上生成一个画布Graphicsg=this.drawingPanel.CreateGraphics();g.Transform=matrix;//这里是画布的显示位置,这里注意x,y的位置是相对于panel左上角的,且注意在进行Matrix变换后,//1像素的单位已经放大为disX,所以这里要除以disX求得实际像素距离floatx=(float)locationX/disX;floaty=(float)locationY/disY;//g.DrawString("abc",font,color,newRectangleF(x,y,(float)displayWidth,(float)displayHeight));
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。