feicuiboy 发表于 2011-4-3 13:01:57

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

=========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, $hFormat, $hBrush) ;绘制字符串($hGraphic图形对象句柄, $string1将被绘制的字符串, $hFont绘制字符串使用的字体的句柄, $aInfo绑定字符串的$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, $hFormat, $hBrush) ;绘制字符串($hGraphic图形对象句柄, $string1将被绘制的字符串, $hFont绘制字符串使用的字体的句柄, $aInfo绑定字符串的$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

netegg 发表于 2011-4-3 17:32:05

印象里是-180到180呀,楼主再看看,要不就是我记错了

feicuiboy 发表于 2011-4-4 11:32:35

回复 2# netegg

90度的时候就无法显示了,因为旋转中心在图像坐上方

feicuiboy 发表于 2011-4-9 18:25:23

TST请教,版大来交流交流呀

gto250 发表于 2011-4-10 15:43:31


#include <GDIPlus.au3>
#include <GDIPlusex.au3>
#include <ScreenCapture.au3>

#include <WinAPI.au3>





_Main("360度旋转")



Func _Main($string1)

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绘制字符串的字符串格式句柄)

$h=_GDIPlus_ImageGetHeight($hImage1)
$w=_GDIPlus_ImageGetWidth($hImage1)
_GDIPlus_GraphicsTranslateTransform( $hGraphic, $w/2, $h/2 )
For $i=0 To 360 Step 45
_GDIPlus_GraphicsRotateTransform( $hGraphic, $i )
_GDIPlus_GraphicsDrawStringEx ($hGraphic, $string1, $hFont, $aInfo, $hFormat, $hBrush) ;绘制字符串($hGraphic图形对象句柄, $string1将被绘制的字符串, $hFont绘制字符串使用的字体的句柄, $aInfo绑定字符串的$tagGDIPRECTF结构, $hFormat绘制字符串的字符串格式句柄, $hBrush绘制字符串的画刷句柄)
Next
_GDIPlus_GraphicsResetTransform( $hGraphic )
_GDIPlus_ImageSaveToFile($hImage1, "GDIPlus_Image"&@SEC&".jpg")


_GDIPlus_ImageDispose($hImage1)

_GDIPlus_ImageDispose($hImage2)

_WinAPI_DeleteObject($hBitmap1)

_WinAPI_DeleteObject($hBitmap2)

_GDIPlus_Shutdown()



EndFunc ;==>_Main


页: [1]
查看完整版本: 问题重提)关于图片加文字水印的问题(如何旋转任意角度文字)