找回密码
 加入
搜索
查看: 2110|回复: 11

如何在一张图片上写上特定的字?

[复制链接]
发表于 2009-3-4 12:44:15 | 显示全部楼层 |阅读模式
如何在一张图片上的某个位置写上特定的文字?

文字是变量,不定的,根据需要的改变的

[ 本帖最后由 ken0137 于 2009-3-10 12:34 编辑 ]
发表于 2009-3-4 15:54:21 | 显示全部楼层
_GDIPlus_GraphicsDrawString
 楼主| 发表于 2009-3-4 19:34:30 | 显示全部楼层
有没有具体点的示例
发表于 2009-3-5 06:28:48 | 显示全部楼层
 楼主| 发表于 2009-3-5 14:41:00 | 显示全部楼层
这个没用,我要的是在图片的特定位置写上文字的
 楼主| 发表于 2009-3-8 09:05:12 | 显示全部楼层
这个是无解????
发表于 2009-3-8 09:30:25 | 显示全部楼层
参看 _GDIPlus_GraphicsDrawStringEx 帮助
_GDIPlus_RectFCreate 设置绘制区域
发表于 2009-3-8 18:02:15 | 显示全部楼层
http://www.autoitx.com/forum.php?mod=viewthread&tid=5599

自己看吧 我在这个例子中在图片上写字了~~~看一下自己应该能明白

再不明白再问我
 楼主| 发表于 2009-3-8 21:07:13 | 显示全部楼层
原帖由 xrbenbeba 于 2009-3-8 18:02 发表
http://www.autoitx.com/forum.php?mod=viewthread&tid=5599

自己看吧 我在这个例子中在图片上写字了~~~看一下自己应该能明白

再不明白再问我

我知道你的这个实例是先做个全屏的GUI,然后把先前截的全屏的图贴到GUI上,
在写点字体上去

我想要的效果是这样的,就是我有一张图片,假设是,1.jpg
我想在这张图片的某个位置写上一些文字,然后保存,
(由于_GDIPlus_GraphicsCreateFromHWND,是需要句柄的,图片好像没有吧,)

[ 本帖最后由 ken0137 于 2009-3-8 21:29 编辑 ]
发表于 2009-3-8 21:42:16 | 显示全部楼层
发表于 2009-3-8 22:46:49 | 显示全部楼层
自己看看吧 au3的实例

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

Opt("MustDeclareVars", 1)

; ===============================================================================================================================
; Description ...: Shows how to emboss text on an image
; Author ........: Paul Campbell (PaulIA)
; Notes .........:
; ===============================================================================================================================

; ===============================================================================================================================
; Global variables
; ===============================================================================================================================
Global $hBitmap, $hImage, $hGraphic, $hFamily, $hFont, $tLayout, $hFormat, $aInfo, $hBrush1, $hBrush2, $iWidth, $iHeight, $hPen
Global $sString="  Created with AutoIt  "

; ===============================================================================================================================
; Main
; ===============================================================================================================================

; Initialize GDI+ library
_GDIPlus_StartUp()

; Capture screen
$hBitmap  = _ScreenCapture_Capture(@MyDocumentsDir & '\AutoItImage.bmp')

; Load image and emboss text
$hImage   = _GDIPlus_ImageLoadFromFile(@MyDocumentsDir & '\AutoItImage.bmp')
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
$hFamily  = _GDIPlus_FontFamilyCreate("Arial")
$hFont    = _GDIPlus_FontCreate($hFamily, 16, 1)
$tLayout  = _GDIPlus_RectFCreate(0, 0)
$hFormat  = _GDIPlus_StringFormatCreate(2)
$hBrush1  = _GDIPlus_BrushCreateSolid(0xA2FFFFFF)
$hBrush2  = _GDIPlus_BrushCreateSolid(0xC4FF0000)
$hPen     = _GDIPlus_PenCreate(0xC4000000, 2)
$aInfo    = _GDIPlus_GraphicsMeasureString($hGraphic, $sString, $hFont, $tLayout, $hFormat)
$iWidth   = DllStructGetData($aInfo[0], "Width" )
$iHeight  = DllStructGetData($aInfo[0], "Height")

_GDIPlus_GraphicsFillRect($hGraphic, 0, 0, $iWidth, $iHeight, $hBrush1)
_GDIPlus_GraphicsDrawRect($hGraphic, 1, 1, $iWidth, $iHeight, $hPen   )
_GDIPlus_GraphicsDrawStringEx($hGraphic, $sString, $hFont, $aInfo[0], $hFormat, $hBrush2)

; Save image
_GDIPlus_ImageSaveToFile($hImage, @MyDocumentsDir & '\AutoItImage2.bmp')

; Free resources
_GDIPlus_PenDispose         ($hPen    )
_GDIPlus_BrushDispose       ($hBrush1 )
_GDIPlus_BrushDispose       ($hBrush2 )
_GDIPlus_StringFormatDispose($hFormat )
_GDIPlus_FontDispose        ($hFont   )
_GDIPlus_FontFamilyDispose  ($hFamily )
_GDIPlus_GraphicsDispose    ($hGraphic)
_GDIPlus_ImageDispose       ($hImage  )
_GDIPlus_ShutDown()

; Show image
Run("MSPaint.exe " & '"' & @MyDocumentsDir & '\AutoItImage2.bmp"')
 楼主| 发表于 2009-3-10 12:33:42 | 显示全部楼层
非常感谢~~~~~~~~~~~~~~~~~
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-18 21:36 , Processed in 0.078923 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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