找回密码
 加入
搜索
查看: 4598|回复: 5

[图形处理] (问题重提)关于图片加文字水印的问题(如何旋转任意角度文字)

  [复制链接]
发表于 2010-7-7 07:30:42 | 显示全部楼层 |阅读模式
本帖最后由 feicuiboy 于 2011-4-3 12:59 编辑

=========2010年的问题============
关于三恨那个图片加文字水印的问题
我想知道(如何旋转文字
看了那个每次只能加一段文字在指定位置,然后就生成图片了,要是我想加多段文字并旋转
放在不同的指定位置,然后再生成图片要怎么写,请各位前辈高人出来指点一下

http://www.autoitx.com/forum.php?mod=viewthread&tid=278&highlight=%CB%AE%D3%A1
==============================2011问题整理后重提=======================


C.L的下面的代码确实可以实现旋转,旋转的中心是图像的左上方的交点。
这样无法试实现 90~270之间的旋转,只能是-90~90°的旋转。
能否有更好的方法,可设置旋转中心。

下面的代码是我根据C.L前辈代码加的注释,欢迎大家交流,高手指点
#include <GDIPlus.au3>

#include <ScreenCapture.au3>

#include <WinAPI.au3>





_Main("80.5","80.5","")



Func _Main($string1,$string2,$string3)

Local $hBitmap1, $hBitmap2, $hImage1, $hImage2, $hGraphic, $width, $height



_GDIPlus_Startup() ;初始化Microsoft Windows GDI+



$hBitmap1 = _ScreenCapture_Capture("") ;捕捉屏幕的一个区域

$hImage1 = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap1) ;从位图句柄创建Bitmap对象 ($hBitmap1)-----HBITMAP句柄

$hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage1) ;获取图像的图形场景 $hImage1---图像对象句柄
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


$hBrush = _GDIPlus_BrushCreateSolid (0xFF000000) ;创建实心画刷对象

$hFormat = _GDIPlus_StringFormatCreate () ;创建字符串格式对象

$hFamily = _GDIPlus_FontFamilyCreate ("Times New Roman") ;创建字体族对象 Times New Roman--------字体族名称

$hFont = _GDIPlus_FontCreate ($hFamily, 50, 0) ;创建字体对象 ($hFamily字样对象的句柄, 50由$iUnit参数指定的单位衡量的字体大小, 0正常字体)

$tLayout = _GDIPlus_RectFCreate (100, 30, 0,0) ;创建$tagGDIPRECTF结构 (350矩形左上角X坐标, 45矩形左上角Y坐标, 0矩形宽度, 0矩形高度) 

$aInfo = _GDIPlus_GraphicsMeasureString ($hGraphic, $String1, $hFont, $tLayout, $hFormat) ;测量字符串尺寸 ($hGraphic图形对象句柄, $String1要绘制的字符串, $hFont绘制字符串使用的字体的句柄, $tLayout绑定字符串的$tagGDIPRECTF结构, $hFormat绘制字符串的字符串格式句柄)

$hMatrix = _GDIPlus_MatrixCreate() ;创建并初始化用以代表矩阵的Matrix对象

$nAngle = 0

_GDIPlus_MatrixRotate($hMatrix, $nAngle, "False") ;旋转矩阵 ($hMatrix--Matrix对象句柄, $nAngle--旋转的角度. 整数指定时钟方向旋转., "False"--True - 指定旋转矩形位于左侧) 

_GDIPlus_GraphicsSetTransform($hGraphic, $hMatrix) ;获取Graphics对象的设备场景的句柄 ($hGraphic--图形对象句柄, $hMatrix--指定世界坐标空间的矩阵对象的句柄) 

_GDIPlus_GraphicsDrawStringEx ($hGraphic, $string1, $hFont, $aInfo[0], $hFormat, $hBrush) ;绘制字符串($hGraphic图形对象句柄, $string1将被绘制的字符串, $hFont绘制字符串使用的字体的句柄, $aInfo[0]绑定字符串的$tagGDIPRECTF结构, $hFormat绘制字符串的字符串格式句柄, $hBrush绘制字符串的画刷句柄) 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


$hBrush = _GDIPlus_BrushCreateSolid (0xFF000000) ;创建实心画刷对象

$hFormat = _GDIPlus_StringFormatCreate () ;创建字符串格式对象

$hFamily = _GDIPlus_FontFamilyCreate ("Times New Roman") ;创建字体族对象 Times New Roman--------字体族名称

$hFont = _GDIPlus_FontCreate ($hFamily, 50, 0) ;创建字体对象 ($hFamily字样对象的句柄, 50由$iUnit参数指定的单位衡量的字体大小, 0正常字体)

$tLayout = _GDIPlus_RectFCreate (100, 30, 0,0) ;创建$tagGDIPRECTF结构 (350矩形左上角X坐标, 45矩形左上角Y坐标, 0矩形宽度, 0矩形高度) 

$aInfo = _GDIPlus_GraphicsMeasureString ($hGraphic, $String1, $hFont, $tLayout, $hFormat) ;测量字符串尺寸 ($hGraphic图形对象句柄, $String1要绘制的字符串, $hFont绘制字符串使用的字体的句柄, $tLayout绑定字符串的$tagGDIPRECTF结构, $hFormat绘制字符串的字符串格式句柄)

$hMatrix = _GDIPlus_MatrixCreate() ;创建并初始化用以代表矩阵的Matrix对象

$nAngle = 50

_GDIPlus_MatrixRotate($hMatrix, $nAngle, "TURE") ;旋转矩阵 ($hMatrix--Matrix对象句柄, $nAngle--旋转的角度. 整数指定时钟方向旋转., "False"--True - 指定旋转矩形位于左侧) 

_GDIPlus_GraphicsSetTransform($hGraphic, $hMatrix) ;获取Graphics对象的设备场景的句柄 ($hGraphic--图形对象句柄, $hMatrix--指定世界坐标空间的矩阵对象的句柄) 

_GDIPlus_GraphicsDrawStringEx ($hGraphic, $string2, $hFont, $aInfo[0], $hFormat, $hBrush) ;绘制字符串($hGraphic图形对象句柄, $string1将被绘制的字符串, $hFont绘制字符串使用的字体的句柄, $aInfo[0]绑定字符串的$tagGDIPRECTF结构, $hFormat绘制字符串的字符串格式句柄, $hBrush绘制字符串的画刷句柄) 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 

_GDIPlus_ImageSaveToFile($hImage1, "GDIPlus_Image"&@SEC&".jpg")


_GDIPlus_ImageDispose($hImage1)

_GDIPlus_ImageDispose($hImage2)

_WinAPI_DeleteObject($hBitmap1)

_WinAPI_DeleteObject($hBitmap2)

_GDIPlus_Shutdown()



EndFunc ;==>_Main

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2010-7-7 23:56:30 | 显示全部楼层
未解决。顶起,知道的出来冒个泡
发表于 2010-7-8 13:59:24 | 显示全部楼层
本帖最后由 C.L 于 2010-7-8 14:06 编辑

没看一楼提供的链接,不过自已写了一段在图片中加旋转文字的代码,代码演示可以加上三段文字,并将每段文字分不同的角度旋转文字,如果你要加多段文字,可以自已按演示代码相应的地方作修改.或者自已将插入旋转文字处的代码改成函数调用更方便点,这样方便循环插入。
#include <GDIPlus.au3>
#include <ScreenCapture.au3>
#include <WinAPI.au3>


_Main("旋转15度","旋转30度","反向旋转30度")

Func _Main($string1,$string2,$string3)
        Local $hBitmap1, $hBitmap2, $hImage1, $hImage2, $hGraphic, $width, $height

        _GDIPlus_Startup()

        $hBitmap1 = _ScreenCapture_Capture("")
        $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap1)
        $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage1)
        
        $hBrush = _GDIPlus_BrushCreateSolid (0xffff0000)
        $hFormat = _GDIPlus_StringFormatCreate ()
        $hFamily = _GDIPlus_FontFamilyCreate ("Times New Roman")
        $hFont = _GDIPlus_FontCreate ($hFamily, 50, 3)
        $tLayout = _GDIPlus_RectFCreate (350, 45, 0, 0)
        $aInfo = _GDIPlus_GraphicsMeasureString ($hGraphic, $String1, $hFont, $tLayout, $hFormat)
        $hMatrix = _GDIPlus_MatrixCreate()
        $nAngle = 15
        _GDIPlus_MatrixRotate($hMatrix, $nAngle, "False")
        _GDIPlus_GraphicsSetTransform($hGraphic, $hMatrix)
        _GDIPlus_GraphicsDrawStringEx ($hGraphic, $string1, $hFont, $aInfo[0], $hFormat, $hBrush)
        
        $hBrush = _GDIPlus_BrushCreateSolid (0xffff0000)
        $hFormat = _GDIPlus_StringFormatCreate ()
        $hFamily = _GDIPlus_FontFamilyCreate ("Times New Roman")
        $hFont = _GDIPlus_FontCreate ($hFamily, 50, 3)
        $tLayout = _GDIPlus_RectFCreate (350,45, 0, 0)
        $aInfo = _GDIPlus_GraphicsMeasureString ($hGraphic, $String1, $hFont, $tLayout, $hFormat)
        $hMatrix = _GDIPlus_MatrixCreate()
        $nAngle = 30
        _GDIPlus_MatrixRotate($hMatrix, $nAngle, "False")
        _GDIPlus_GraphicsSetTransform($hGraphic, $hMatrix)
        _GDIPlus_GraphicsDrawStringEx ($hGraphic, $string2, $hFont, $aInfo[0], $hFormat, $hBrush)
        
        $hBrush = _GDIPlus_BrushCreateSolid (0xff000000)
        $hFormat = _GDIPlus_StringFormatCreate ()
        $hFamily = _GDIPlus_FontFamilyCreate ("Times New Roman")
        $hFont = _GDIPlus_FontCreate ($hFamily, 50, 3)
        $tLayout = _GDIPlus_RectFCreate (300, 550, 0, 0)
        $aInfo = _GDIPlus_GraphicsMeasureString ($hGraphic, $String3, $hFont, $tLayout, $hFormat)
        $hMatrix = _GDIPlus_MatrixCreate()
        $nAngle = -30
        _GDIPlus_MatrixRotate($hMatrix, $nAngle, "False")
        _GDIPlus_GraphicsSetTransform($hGraphic, $hMatrix)
        _GDIPlus_GraphicsDrawStringEx ($hGraphic, $string3, $hFont, $aInfo[0], $hFormat, $hBrush)

        _GDIPlus_ImageSaveToFile($hImage1, "GDIPlus_Image.jpg")

        _GDIPlus_ImageDispose($hImage1)
        _GDIPlus_ImageDispose($hImage2)
        _WinAPI_DeleteObject($hBitmap1)
        _WinAPI_DeleteObject($hBitmap2)
        _GDIPlus_Shutdown()

EndFunc   ;==>_Main
效果图:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×

评分

参与人数 2威望 +3 金钱 +62 收起 理由
feicuiboy + 12 欢迎交流指导
afan + 3 + 50 精品文章

查看全部评分

发表于 2010-7-8 14:32:39 | 显示全部楼层
呵呵,学习一下。。
发表于 2010-7-8 17:54:55 | 显示全部楼层
3L的确实可以!
发表于 2010-7-9 08:18:44 | 显示全部楼层
不错啊,谢谢分享!!!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-10 06:55 , Processed in 0.102474 second(s), 28 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表