代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
CSharp
】
WinFrom程序如何从数据库循环读取图片并合成
作者:
Dezai.CN
/ 发布于
2012/5/10
/
561
数据库中有表backgroundimage(背景图片表),backgroundpoint(图片坐标表),systemheadimage(头像表),分别存放的背景,坐标及头像,我现在要对应遍历出三表相关信息并合成一张图片,
<div> <span style="color: #0000ff">using</span><span style="color: #000000"> System; </span><span style="color: #0000ff">using</span><span style="color: #000000"> System.Collections.Generic; </span><span style="color: #0000ff">using</span><span style="color: #000000"> System.Text; </span><span style="color: #0000ff">using</span><span style="color: #000000"> System.Drawing; </span><span style="color: #0000ff">using</span><span style="color: #000000"> System.Drawing.Drawing2D; </span><span style="color: #0000ff">namespace</span><span style="color: #000000"> BaiShun { </span><span style="color: #0000ff">public</span><span style="color: #0000ff">class</span><span style="color: #000000"> Helper { </span><span style="color: #0000ff">#region</span><span style="color: #000000"> Helper</span><span style="color: #000000"> </span><span style="color: #808080">///</span><span style="color: #808080"><summary></span><span style="color: #008000"> </span><span style="color: #808080">///</span><span style="color: #008000"> 原图的大小 </span><span style="color: #808080">///</span><span style="color: #808080"></summary></span><span style="color: #808080"> </span><span style="color: #0000ff">public</span><span style="color: #0000ff">int</span><span style="color: #000000"> calcWidth(</span><span style="color: #0000ff">int</span><span style="color: #000000"> h, Image image) { </span><span style="color: #0000ff">int</span><span style="color: #000000"> w </span><span style="color: #000000">=</span><span style="color: #800080">0</span><span style="color: #000000">; </span><span style="color: #008000">//</span><span style="color: #008000">计算比例 </span><span style="color: #008000">//</span><span style="color: #008000">w/h = nw/x x*w = h*nw; x = h*nw/w </span><span style="color: #008000"> </span><span style="color: #000000">w </span><span style="color: #000000">=</span><span style="color: #000000">Convert.ToInt32( image.Width </span><span style="color: #000000">*</span><span style="color: #000000"> h </span><span style="color: #000000">/</span><span style="color: #000000"> image.Height); </span><span style="color: #0000ff">return</span><span style="color: #000000"> w; } </span><span style="color: #808080">///</span><span style="color: #808080"><summary></span><span style="color: #008000"> </span><span style="color: #808080">///</span><span style="color: #008000"> 计算两点间长度 </span><span style="color: #808080">///</span><span style="color: #808080"></summary></span><span style="color: #808080"> </span><span style="color: #0000ff">public</span><span style="color: #0000ff">int</span><span style="color: #000000"> getLength(</span><span style="color: #0000ff">int</span><span style="color: #000000"> x1, </span><span style="color: #0000ff">int</span><span style="color: #000000"> y1, </span><span style="color: #0000ff">int</span><span style="color: #000000"> x2, </span><span style="color: #0000ff">int</span><span style="color: #000000"> y2) { </span><span style="color: #0000ff">double</span><span style="color: #000000"> distance </span><span style="color: #000000">=</span><span style="color: #000000"> Math.Pow(Math.Pow((x1 </span><span style="color: #000000">-</span><span style="color: #000000"> x2), </span><span style="color: #800080">2</span><span style="color: #000000">) </span><span style="color: #000000">+</span><span style="color: #000000"> Math.Pow((y1 </span><span style="color: #000000">-</span><span style="color: #000000"> y2), </span><span style="color: #800080">2</span><span style="color: #000000">), </span><span style="color: #800080">0.5</span><span style="color: #000000">); </span><span style="color: #0000ff">return</span><span style="color: #000000"> Convert.ToInt32( distance); } </span><span style="color: #808080">///</span><span style="color: #808080"><summary></span><span style="color: #008000"> </span><span style="color: #808080">///</span><span style="color: #008000"> 计算角度 </span><span style="color: #808080">///</span><span style="color: #808080"></summary></span><span style="color: #008000"> </span><span style="color: #808080">///</span><span style="color: #808080"><param name="px1"></span><span style="color: #008000">p1 X轴</span><span style="color: #808080"></param></span><span style="color: #008000"> </span><span style="color: #808080">///</span><span style="color: #808080"><param name="py1"></span><span style="color: #008000">p1 y轴</span><span style="color: #808080"></param></span><span style="color: #008000"> </span><span style="color: #808080">///</span><span style="color: #808080"><param name="px2"></span><span style="color: #008000">p2 X轴</span><span style="color: #808080"></param></span><span style="color: #008000"> </span><span style="color: #808080">///</span><span style="color: #808080"><param name="py2"></span><span style="color: #008000">p2 y轴</span><span style="color: #808080"></param></span><span style="color: #008000"> </span><span style="color: #808080">///</span><span style="color: #808080"><returns></returns></span><span style="color: #808080"> </span><span style="color: #0000ff">public</span><span style="color: #0000ff">double</span><span style="color: #000000"> getAngle(</span><span style="color: #0000ff">double</span><span style="color: #000000"> px1, </span><span style="color: #0000ff">double</span><span style="color: #000000"> py1, </span><span style="color: #0000ff">double</span><span style="color: #000000"> px2, </span><span style="color: #0000ff">double</span><span style="color: #000000"> py2) { </span><span style="color: #0000ff">double</span><span style="color: #000000"> x </span><span style="color: #000000">=</span><span style="color: #000000"> px2 </span><span style="color: #000000">-</span><span style="color: #000000"> px1; </span><span style="color: #0000ff">double</span><span style="color: #000000"> y </span><span style="color: #000000">=</span><span style="color: #000000"> py2 </span><span style="color: #000000">-</span><span style="color: #000000"> py1; </span><span style="color: #0000ff">double</span><span style="color: #000000"> hyp </span><span style="color: #000000">=</span><span style="color: #000000"> Math.Sqrt(Math.Pow(x, </span><span style="color: #800080">2</span><span style="color: #000000">) </span><span style="color: #000000">+</span><span style="color: #000000"> Math.Pow(y, </span><span style="color: #800080">2</span><span style="color: #000000">)); </span><span style="color: #0000ff">double</span><span style="color: #000000"> cos </span><span style="color: #000000">=</span><span style="color: #000000"> x </span><span style="color: #000000">/</span><span style="color: #000000"> hyp; </span><span style="color: #0000ff">double</span><span style="color: #000000"> rad </span><span style="color: #000000">=</span><span style="color: #000000"> Math.Acos(cos); </span><span style="color: #0000ff">double</span><span style="color: #000000"> deg </span><span style="color: #000000">=</span><span style="color: #800080">180</span><span style="color: #000000">/</span><span style="color: #000000"> (Math.PI </span><span style="color: #000000">/</span><span style="color: #000000"> rad); </span><span style="color: #0000ff">if</span><span style="color: #000000"> (y </span><span style="color: #000000"><</span><span style="color: #800080">0</span><span style="color: #000000">) { deg </span><span style="color: #000000">=</span><span style="color: #000000">-</span><span style="color: #000000">deg; } </span><span style="color: #0000ff">else</span><span style="color: #0000ff">if</span><span style="color: #000000"> ((y </span><span style="color: #000000">==</span><span style="color: #800080">0</span><span style="color: #000000">) </span><span style="color: #000000">&&</span><span style="color: #000000"> (x </span><span style="color: #000000"><</span><span style="color: #800080">0</span><span style="color: #000000">)) { deg </span><span style="color: #000000">=</span><span style="color: #800080">180</span><span style="color: #000000">; } </span><span style="color: #0000ff">return</span><span style="color: #000000"> deg; } </span><span style="color: #808080">///</span><span style="color: #808080"><summary></span><span style="color: #008000"> </span><span style="color: #808080">///</span><span style="color: #008000"> 计算角度 </span><span style="color: #808080">///</span><span style="color: #808080"></summary></span><span style="color: #808080"> </span><span style="color: #0000ff">public</span><span style="color: #000000"> Image RotateImg(Image b, </span><span style="color: #0000ff">int</span><span style="color: #000000"> angle) { angle </span><span style="color: #000000">=</span><span style="color: #000000"> angle </span><span style="color: #000000">%</span><span style="color: #800080">360</span><span style="color: #000000">; </span><span style="color: #008000">//</span><span style="color: #008000">弧度转换</span><span style="color: #008000"> </span><span style="color: #0000ff">double</span><span style="color: #000000"> radian </span><span style="color: #000000">=</span><span style="color: #000000"> angle </span><span style="color: #000000">*</span><span style="color: #000000"> Math.PI </span><span style="color: #000000">/</span><span style="color: #800080">180.0</span><span style="color: #000000">; </span><span style="color: #0000ff">double</span><span style="color: #000000"> cos </span><span style="color: #000000">=</span><span style="color: #000000"> Math.Cos(radian); </span><span style="color: #0000ff">double</span><span style="color: #000000"> sin </span><span style="color: #000000">=</span><span style="color: #000000"> Math.Sin(radian); </span><span style="color: #008000">//</span><span style="color: #008000">原图的宽和高</span><span style="color: #008000"> </span><span style="color: #0000ff">int</span><span style="color: #000000"> w </span><span style="color: #000000">=</span><span style="color: #000000"> b.Width; </span><span style="color: #0000ff">int</span><span style="color: #000000"> h </span><span style="color: #000000">=</span><span style="color: #000000"> b.Height; </span><span style="color: #0000ff">int</span><span style="color: #000000"> W </span><span style="color: #000000">=</span><span style="color: #000000"> (</span><span style="color: #0000ff">int</span><span style="color: #000000">)(Math.Max(Math.Abs(w </span><span style="color: #000000">*</span><span style="color: #000000"> cos </span><span style="color: #000000">-</span><span style="color: #000000"> h </span><span style="color: #000000">*</span><span style="color: #000000"> sin), Math.Abs(w </span><span style="color: #000000">*</span><span style="color: #000000"> cos </span><span style="color: #000000">+</span><span style="color: #000000"> h </span><span style="color: #000000">*</span><span style="color: #000000"> sin))); </span><span style="color: #0000ff">int</span><span style="color: #000000"> H </span><span style="color: #000000">=</span><span style="color: #000000"> (</span><span style="color: #0000ff">int</span><span style="color: #000000">)(Math.Max(Math.Abs(w </span><span style="color: #000000">*</span><span style="color: #000000"> sin </span><span style="color: #000000">-</span><span style="color: #000000"> h </span><span style="color: #000000">*</span><span style="color: #000000"> cos), Math.Abs(w </span><span style="color: #000000">*</span><span style="color: #000000"> sin </span><span style="color: #000000">+</span><span style="color: #000000"> h </span><span style="color: #000000">*</span><span style="color: #000000"> cos))); </span><span style="color: #008000">//</span><span style="color: #008000">目标位图</span><span style="color: #008000"> </span><span style="color: #000000">Bitmap dsImage </span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000"> Bitmap(W, H); Graphics g </span><span style="color: #000000">=</span><span style="color: #000000"> Graphics.FromImage(dsImage); </span><span style="color: #008000">/*</span><span style="color: #008000">坐标结束</span><span style="color: #008000">*/</span><span style="color: #000000"> g.InterpolationMode </span><span style="color: #000000">=</span><span style="color: #000000"> InterpolationMode.Default;</span><span style="color: #008000">//</span><span style="color: #008000">Bilinear;</span><span style="color: #008000"> </span><span style="color: #000000">g.SmoothingMode </span><span style="color: #000000">=</span><span style="color: #000000"> SmoothingMode.Default;</span><span style="color: #008000">//</span><span style="color: #008000"> HighQuality; </span><span style="color: #008000">//</span><span style="color: #008000">计算偏移量</span><span style="color: #008000"> </span><span style="color: #000000">Point Offset </span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000"> Point((W </span><span style="color: #000000">-</span><span style="color: #000000"> w) </span><span style="color: #000000">/</span><span style="color: #800080">2</span><span style="color: #000000">, (H </span><span style="color: #000000">-</span><span style="color: #000000"> h) </span><span style="color: #000000">/</span><span style="color: #800080">2</span><span style="color: #000000">); </span><span style="color: #008000">//</span><span style="color: #008000">构造图像显示区域:让图像的中心与窗口的中心点一致</span><span style="color: #008000"> </span><span style="color: #000000">Rectangle rect </span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000"> Rectangle(Offset.X, Offset.Y, w, h); Point center </span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000"> Point(rect.X </span><span style="color: #000000">+</span><span style="color: #000000"> rect.Width </span><span style="color: #000000">/</span><span style="color: #800080">2</span><span style="color: #000000">, rect.Y </span><span style="color: #000000">+</span><span style="color: #000000"> rect.Height </span><span style="color: #000000">/</span><span style="color: #800080">2</span><span style="color: #000000">); g.TranslateTransform(center.X, center.Y); g.RotateTransform(</span><span style="color: #800080">360</span><span style="color: #000000">-</span><span style="color: #000000"> angle); </span><span style="color: #008000">//</span><span style="color: #008000">恢复图像在水平和垂直方向的平移</span><span style="color: #008000"> </span><span style="color: #000000">g.TranslateTransform(</span><span style="color: #000000">-</span><span style="color: #000000">center.X, </span><span style="color: #000000">-</span><span style="color: #000000">center.Y); g.DrawImage(b, rect); </span><span style="color: #008000">//</span><span style="color: #008000">重至绘图的所有变换</span><span style="color: #008000"> </span><span style="color: #000000">g.ResetTransform(); g.Save(); g.Dispose(); b.Dispose(); </span><span style="color: #0000ff">return</span><span style="color: #000000"> dsImage; } </span><span style="color: #808080">///</span><span style="color: #808080"><summary></span><span style="color: #008000"> </span><span style="color: #808080">///</span><span style="color: #008000"> 厘米转像素 根据drawGraphicsDPI—X轴 </span><span style="color: #808080">///</span><span style="color: #808080"></summary></span><span style="color: #808080"> </span><span style="color: #0000ff">public</span><span style="color: #0000ff">int</span><span style="color: #000000"> cm_To_px_ByX(</span><span style="color: #0000ff">int</span><span style="color: #000000"> length) { </span><span style="color: #0000ff">return</span><span style="color: #000000"> Convert.ToInt32(length </span><span style="color: #000000">*</span><span style="color: #800080">72</span><span style="color: #000000">/</span><span style="color: #800080">2.54</span><span style="color: #000000">); } </span><span style="color: #808080">///</span><span style="color: #808080"><summary></span><span style="color: #008000"> </span><span style="color: #808080">///</span><span style="color: #008000"> 厘米转像素 根据drawGraphicsDPI—Y轴 </span><span style="color: #808080">///</span><span style="color: #808080"></summary></span><span style="color: #808080"> </span><span style="color: #0000ff">public</span><span style="color: #0000ff">int</span><span style="color: #000000"> cm_To_px_ByY(</span><span style="color: #0000ff">int</span><span style="color: #000000"> width) { </span><span style="color: #0000ff">return</span><span style="color: #000000"> Convert.ToInt32(width </span><span style="color: #000000">*</span><span style="color: #800080">72</span><span style="color: #000000">/</span><span style="color: #800080">2.54</span><span style="color: #000000">); } </span><span style="color: #808080">///</span><span style="color: #808080"><summary></span><span style="color: #008000"> </span><span style="color: #808080">///</span><span style="color: #008000"> 像素转厘米 根据drawGraphicsDPI—X轴 </span><span style="color: #808080">///</span><span style="color: #808080"></summary></span><span style="color: #808080"> </span><span style="color: #0000ff">public</span><span style="color: #0000ff">float</span><span style="color: #000000"> px_To_cm_ByX(</span><span style="color: #0000ff">int</span><span style="color: #000000"> length) { </span><span style="color: #0000ff">return</span><span style="color: #000000"> Convert.ToSingle(length </span><span style="color: #000000">*</span><span style="color: #800080">2.54</span><span style="color: #000000">/</span><span style="color: #800080">72</span><span style="color: #000000">); } </span><span style="color: #808080">///</span><span style="color: #808080"><summary></span><span style="color: #008000"> </span><span style="color: #808080">///</span><span style="color: #008000"> 像素转厘米 根据drawGraphicsDPI—Y轴 </span><span style="color: #808080">///</span><span style="color: #808080"></summary></span><span style="color: #808080"> </span><span style="color: #0000ff">public</span><span style="color: #0000ff">int</span><span style="color: #000000"> px_To_cm_ByY(</span><span style="color: #0000ff">int</span><span style="color: #000000"> width) { </span><span style="color: #0000ff">return</span><span style="color: #000000"> Convert.ToInt32(width </span><span style="color: #000000">*</span><span style="color: #800080">2.54</span><span style="color: #000000">/</span><span style="color: #800080">72</span><span style="color: #000000">); } </span><span style="color: #0000ff">#endregion</span><span style="color: #000000"> Helper</span><span style="color: #000000"> } } </span><span style="color: #0000ff">using</span><span style="color: #000000"> System; </span><span style="color: #0000ff">using</span><span style="color: #000000"> System.Collections.Generic; </span><span style="color: #0000ff">using</span><span style="color: #000000"> System.Text; </span><span style="color: #0000ff">using</span><span style="color: #000000"> System.Drawing; </span><span style="color: #0000ff">namespace</span><span style="color: #000000"> BaiShun { </span><span style="color: #0000ff">public</span><span style="color: #0000ff">class</span><span style="color: #000000"> SyntheticHelper { </span><span style="color: #0000ff">private</span><span style="color: #0000ff">static</span><span style="color: #000000"> Helper helper </span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000"> Helper(); </span><span style="color: #808080">///</span><span style="color: #808080"><summary></span><span style="color: #008000"> </span><span style="color: #808080">///</span><span style="color: #008000"> 设置图片 </span><span style="color: #808080">///</span><span style="color: #808080"></summary></span><span style="color: #808080"> </span><span style="color: #0000ff">public</span><span style="color: #0000ff">static</span><span style="color: #000000"> Image settingPic(Image originalBackgroundImage, Image originalHeadImage, </span><span style="color: #0000ff">int</span><span style="color: #000000"> p1_X, </span><span style="color: #0000ff">int</span><span style="color: #000000"> p1_Y, </span><span style="color: #0000ff">int</span><span style="color: #000000"> p2_X, </span><span style="color: #0000ff">int</span><span style="color: #000000"> p2_Y) { </span><span style="color: #808080">///</span><span style="color: #008000">************************绘制背景************************/</span><span style="color: #808080"> </span><span style="color: #008000">//</span><span style="color: #008000">1. 新建backgroundImage。</span><span style="color: #008000"> </span><span style="color: #000000">Image backgroundImage </span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000"> Bitmap(originalBackgroundImage.Width, originalBackgroundImage.Height); </span><span style="color: #008000">//</span><span style="color: #008000">2. drawBackgroundImagePoint定义backgroundImage背景坐标系</span><span style="color: #008000"> </span><span style="color: #000000">Point[] drawBackgroundImagePoint </span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000"> Point[] { </span><span style="color: #0000ff">new</span><span style="color: #000000"> Point(</span><span style="color: #800080">0</span><span style="color: #000000">, </span><span style="color: #800080">0</span><span style="color: #000000">), </span><span style="color: #0000ff">new</span><span style="color: #000000"> Point(originalBackgroundImage.Width, </span><span style="color: #800080">0</span><span style="color: #000000">), </span><span style="color: #0000ff">new</span><span style="color: #000000"> Point(</span><span style="color: #800080">0</span><span style="color: #000000">, originalBackgroundImage.Height) }; </span><span style="color: #008000">//</span><span style="color: #008000"> 获得图面</span><span style="color: #008000"> </span><span style="color: #000000">Graphics drawGraphicsBackground </span><span style="color: #000000">=</span><span style="color: #000000"> Graphics.FromImage(backgroundImage); </span><span style="color: #008000">//</span><span style="color: #008000">3. 将originalBackgroundImage原始背景图绘制上去(backgroundImage)</span><span style="color: #008000"> </span><span style="color: #000000">drawGraphicsBackground.DrawImage(originalBackgroundImage, drawBackgroundImagePoint); drawGraphicsBackground.Dispose(); </span><span style="color: #008000">//</span><span style="color: #008000">backgroundImage </span><span style="color: #008000">//</span><span style="color: #008000">***********************头像***********************</span><span style="color: #008000"> </span><span style="color: #0000ff">int</span><span style="color: #000000"> tempY </span><span style="color: #000000">=</span><span style="color: #000000"> p2_Y </span><span style="color: #000000">-</span><span style="color: #000000"> p1_Y; </span><span style="color: #0000ff">int</span><span style="color: #000000"> tempX </span><span style="color: #000000">=</span><span style="color: #000000"> p2_X </span><span style="color: #000000">-</span><span style="color: #000000"> p1_X; </span><span style="color: #0000ff">double</span><span style="color: #000000"> radian </span><span style="color: #000000">=</span><span style="color: #000000"> Math.Atan2((</span><span style="color: #0000ff">double</span><span style="color: #000000">)(tempY), (</span><span style="color: #0000ff">double</span><span style="color: #000000">)(tempX)); </span><span style="color: #0000ff">int</span><span style="color: #000000"> angle1 </span><span style="color: #000000">=</span><span style="color: #000000"> Convert.ToInt32(radian </span><span style="color: #000000">*</span><span style="color: #000000"> (</span><span style="color: #800080">180</span><span style="color: #000000">/</span><span style="color: #000000"> Math.PI)); radian </span><span style="color: #000000">=</span><span style="color: #000000"> angle1 </span><span style="color: #000000">*</span><span style="color: #000000"> (Math.PI </span><span style="color: #000000">/</span><span style="color: #800080">180</span><span style="color: #000000">); </span><span style="color: #0000ff">double</span><span style="color: #000000"> t1 </span><span style="color: #000000">=</span><span style="color: #000000"> Math.Cos(radian); </span><span style="color: #0000ff">double</span><span style="color: #000000"> t2 </span><span style="color: #000000">=</span><span style="color: #000000"> Math.Sin(radian); </span><span style="color: #0000ff">double</span><span style="color: #000000"> t3 </span><span style="color: #000000">=</span><span style="color: #000000"> Math.Cos(</span><span style="color: #000000">-</span><span style="color: #000000">radian); </span><span style="color: #0000ff">double</span><span style="color: #000000"> t4 </span><span style="color: #000000">=</span><span style="color: #000000"> Math.Sin(</span><span style="color: #000000">-</span><span style="color: #000000">radian); </span><span style="color: #008000">/*</span><span style="color: #008000">追加的素材图片</span><span style="color: #008000">*/</span><span style="color: #000000"> </span><span style="color: #008000">//</span><span style="color: #008000"> *1. 根据p1,p2点计算两点间的距离。可以得出缩放图片的高度h</span><span style="color: #008000"> </span><span style="color: #0000ff">int</span><span style="color: #000000"> h </span><span style="color: #000000">=</span><span style="color: #000000"> helper.getLength(p1_X, p1_Y, p2_X, p2_Y); </span><span style="color: #008000">//</span><span style="color: #008000"> *2. 根据h计算出w</span><span style="color: #008000"> </span><span style="color: #0000ff">int</span><span style="color: #000000"> w </span><span style="color: #000000">=</span><span style="color: #000000"> helper.calcWidth(h, originalHeadImage); </span><span style="color: #008000">//</span><span style="color: #008000">1. 计算缩放长宽,使用originalHeadImage创建zoomImage图片。(图片已被缩放)</span><span style="color: #008000"> </span><span style="color: #000000">Bitmap zoomImage </span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000"> Bitmap(originalHeadImage, w, h); </span><span style="color: #008000">//</span><span style="color: #008000">2. 根据坐标p1,p2点计算角度angle(公式A)</span><span style="color: #008000"> </span><span style="color: #0000ff">double</span><span style="color: #000000"> angle </span><span style="color: #000000">=</span><span style="color: #000000">Math.Abs( helper.getAngle(p1_X, p1_Y, p2_X, p2_Y)); </span><span style="color: #008000">//</span><span style="color: #008000"> double radian = angle * (Math.PI / 180); </span><span style="color: #008000">//</span><span style="color: #008000">3. 根据zoomImage计算旋转图形生成rotateImage</span><span style="color: #008000"> </span><span style="color: #000000">Image rotateImage </span><span style="color: #000000">=</span><span style="color: #000000"> helper.RotateImg(zoomImage, Convert.ToInt32(</span><span style="color: #000000">-</span><span style="color: #800080">90</span><span style="color: #000000">+</span><span style="color: #000000"> Math.Abs(angle))); </span><span style="color: #008000">//</span><span style="color: #008000">4. 将angle绝对值修正成正坐标。 </span><span style="color: #008000">//</span><span style="color: #008000">angle = angle); </span><span style="color: #008000">//</span><span style="color: #008000">5. 取得backgroundImage背景绘画方法。准备绘图</span><span style="color: #008000"> </span><span style="color: #000000">Graphics drawGraphics </span><span style="color: #000000">=</span><span style="color: #000000"> Graphics.FromImage(backgroundImage); </span><span style="color: #008000">//</span><span style="color: #008000">6. 计算修正坐标[Revised_X]和[Revised_Y]。</span><span style="color: #008000"> </span><span style="color: #0000ff">int</span><span style="color: #000000"> Revised_X </span><span style="color: #000000">=</span><span style="color: #000000"> Convert.ToInt32(Math.Cos(</span><span style="color: #800080">90</span><span style="color: #000000">-</span><span style="color: #000000"> angle) </span><span style="color: #000000">*</span><span style="color: #000000"> (w </span><span style="color: #000000">/</span><span style="color: #800080">2</span><span style="color: #000000">)); </span><span style="color: #0000ff">int</span><span style="color: #000000"> Revised_Y </span><span style="color: #000000">=</span><span style="color: #000000"> Convert.ToInt32(Math.Sin(</span><span style="color: #800080">90</span><span style="color: #000000">-</span><span style="color: #000000"> angle) </span><span style="color: #000000">*</span><span style="color: #000000"> (w </span><span style="color: #000000">/</span><span style="color: #800080">2</span><span style="color: #000000">)); </span><span style="color: #008000">//</span><span style="color: #008000">7. 声明p3点</span><span style="color: #008000"> </span><span style="color: #0000ff">int</span><span style="color: #000000"> p3_X </span><span style="color: #000000">=</span><span style="color: #800080">0</span><span style="color: #000000">; </span><span style="color: #0000ff">int</span><span style="color: #000000"> p3_Y </span><span style="color: #000000">=</span><span style="color: #800080">0</span><span style="color: #000000">; </span><span style="color: #008000">//</span><span style="color: #008000">8. 判断</span><span style="color: #008000"> </span><span style="color: #0000ff">if</span><span style="color: #000000"> (p1_X </span><span style="color: #000000">==</span><span style="color: #000000"> p2_X </span><span style="color: #000000">||</span><span style="color: #000000"> p1_Y </span><span style="color: #000000">==</span><span style="color: #000000"> p2_Y) { </span><span style="color: #008000">//</span><span style="color: #008000">如果是垂直形[坐标位置直接减去rotateImage宽度的一半]。</span><span style="color: #008000"> </span><span style="color: #000000">p3_X </span><span style="color: #000000">=</span><span style="color: #000000"> Convert.ToInt32(p2_X </span><span style="color: #000000">-</span><span style="color: #000000"> Math.Abs(Revised_X)); p3_Y </span><span style="color: #000000">=</span><span style="color: #000000"> Convert.ToInt32(p2_Y </span><span style="color: #000000">+</span><span style="color: #000000"> Math.Abs(Revised_Y)); </span><span style="color: #008000">//</span><span style="color: #008000">垂直型 </span><span style="color: #008000">//</span><span style="color: #008000"> 9.绘制图形输出</span><span style="color: #008000"> </span><span style="color: #000000">drawGraphics.DrawImage(rotateImage, </span><span style="color: #0000ff">new</span><span style="color: #000000"> Point(p3_X, p3_Y)); } </span><span style="color: #0000ff">else</span><span style="color: #000000"> { </span><span style="color: #008000">//</span><span style="color: #008000"> drawGraphics.TranslateTransform(0, 140);</span><span style="color: #008000">//</span><span style="color: #008000"> 平移到5,5坐标 </span><span style="color: #008000"> </span><span style="color: #000000"> </span><span style="color: #0000ff">double</span><span style="color: #000000"> temp </span><span style="color: #000000">=</span><span style="color: #000000"> Math.Sin(radian); temp </span><span style="color: #000000">/=</span><span style="color: #800080">2</span><span style="color: #000000">; </span><span style="color: #0000ff">double</span><span style="color: #000000"> temp2 </span><span style="color: #000000">=</span><span style="color: #000000"> Math.Cos(radian); p3_X </span><span style="color: #000000">=</span><span style="color: #000000"> Convert.ToInt32((</span><span style="color: #0000ff">float</span><span style="color: #000000">)p1_X </span><span style="color: #000000">+</span><span style="color: #000000"> (</span><span style="color: #0000ff">float</span><span style="color: #000000">)w </span><span style="color: #000000">*</span><span style="color: #000000"> temp ); p3_Y </span><span style="color: #000000">=</span><span style="color: #000000"> Convert.ToInt32((</span><span style="color: #0000ff">float</span><span style="color: #000000">)p1_Y </span><span style="color: #000000">+</span><span style="color: #000000"> (</span><span style="color: #0000ff">float</span><span style="color: #000000">)h </span><span style="color: #000000">*</span><span style="color: #000000"> Math.Sin(radian) </span><span style="color: #000000">-</span><span style="color: #000000"> w </span><span style="color: #000000">*</span><span style="color: #000000"> temp2 </span><span style="color: #000000">/</span><span style="color: #800080">2</span><span style="color: #000000">); </span><span style="color: #008000">//</span><span style="color: #008000">其它型 </span><span style="color: #008000">//</span><span style="color: #008000"> 9.绘制图形输出</span><span style="color: #008000"> </span><span style="color: #000000">drawGraphics.DrawImage(rotateImage, </span><span style="color: #0000ff">new</span><span style="color: #000000"> Point(p3_X, p3_Y)); } drawGraphics.Dispose(); </span><span style="color: #0000ff">return</span><span style="color: #000000"> backgroundImage; } </span><span style="color: #808080">///</span><span style="color: #808080"><summary></span><span style="color: #008000"> </span><span style="color: #808080">///</span><span style="color: #008000"> 设置文字 </span><span style="color: #808080">///</span><span style="color: #808080"></summary></span><span style="color: #808080"> </span><span style="color: #0000ff">public</span><span style="color: #0000ff">static</span><span style="color: #000000"> Image settingFont(Image image, String Text, </span><span style="color: #0000ff">int</span><span style="color: #000000"> x, </span><span style="color: #0000ff">int</span><span style="color: #000000"> y) { </span><span style="color: #008000">//</span><span style="color: #008000">获得画笔</span><span style="color: #008000"> </span><span style="color: #000000">Graphics drawGraphicsFont </span><span style="color: #000000">=</span><span style="color: #000000"> Graphics.FromImage(image); Brush brush </span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000"> System.Drawing.SolidBrush(System.Drawing.Color.Black); </span><span style="color: #008000">//</span><span style="color: #008000">绘制文字</span><span style="color: #008000"> </span><span style="color: #000000">drawGraphicsFont.DrawString(Text, </span><span style="color: #0000ff">new</span><span style="color: #000000"> Font(</span><span style="color: #800000">"</span><span style="color: #800000">宋体</span><span style="color: #800000">"</span><span style="color: #000000">, </span><span style="color: #800080">15</span><span style="color: #000000">), brush, x, y); drawGraphicsFont.Dispose(); </span><span style="color: #0000ff">return</span><span style="color: #000000"> image; } } } </span> </div>
试试其它关键字
循环读取图片
同语言下
.
文件IO 操作类库
.
Check图片类型[JPEG(.jpg 、.jpeg),TIF,GIF,BMP,PNG,P
.
机器名和IP取得(IPV4 IPV6)
.
Tiff转换Bitmap
.
linqHelper
.
MadieHelper.cs
.
RegHelper.cs
.
如果关闭一个窗体后激活另一个窗体的事件或方法
.
创建日志通用类
.
串口辅助开发类
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
Dezai.CN
贡献的其它代码
(
4037
)
.
多线程Socket服务器模块
.
生成随机密码
.
清除浮动样式
.
弹出窗口居中
.
抓取url的函数
.
使用base HTTP验证
.
div模拟iframe嵌入效果
.
通过header转向的方法
.
Session操作类
.
执行sqlite输入插入操作后获得自动编号的ID
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3