以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  绘制图片,文字怎么旋转90度  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=120482)

--  作者:mamuaiqing
--  发布时间:2018/6/16 22:34:00
--  绘制图片,文字怎么旋转90度

Dim imgback As image = getimage("C:\\图片.jpg")
Dim bmp As new bitmap(imgback.width, imgback.height) 

Dim g = graphics.fromimage(bmp)
g.DrawImage(imgback, 0, 0, imgback.Width, imgback.Height)
Dim fnt As New Font("宋体",12,FontStyle.Bold)
Dim msg As String = "Foxtable"
g.DrawString(msg,fnt,Brushes.Gray,100,347)
bmp.Save("f:\\新图片.jpg")
bmp.dispose
如题:怎么将写入图片中的的文字"Foxtable"旋转90度,请教老师,谢谢


--  作者:有点甜
--  发布时间:2018/6/17 15:25:00
--  

Dim imgback As image = getimage("d:\\test.jpg")
Dim w As Integer = imgback.width
Dim h As Integer = imgback.height

Dim angle As Double = 45
Dim a As Double = angle Mod 360


Dim radian As Double = a * Math.PI / 180.0
Dim cos As Double = Math.Cos(radian)
Dim sin As Double = Math.Sin(radian)

Dim newW As Integer = Math.Max(Math.Abs(w * cos - h * sin), Math.Abs(w * cos + h * sin))
Dim newH As Integer = Math.Max(Math.Abs(w * sin - h * cos), Math.Abs(w * sin + h * cos))

Dim bmpSrc As new Bitmap(newW, newH)
Dim g = Graphics.FromImage(bmpSrc)
g.DrawImage(imgback, 0, 0, imgback.Width, imgback.Height)

\'g.FillRectangle(Brushes.Red,0,0,newW,newH)

g.TranslateTransform(newW/2, newH/2)
g.RotateTransform(angle)
g.TranslateTransform(-newW/2, -newH/2)
Dim x As Integer = (newW-w)/2
Dim y As Integer = (newH-h)/2

Dim fnt As New Font("宋体",16)
Dim msg As String = "I Like Foxtable"
g.DrawString(msg,fnt,Brushes.Red,x,y)


bmpSrc.Save("d:\\test2.jpg")

g.Dispose()
bmpSrc.Dispose