第十一讲 GDI+画笔之补充 画笔的缩放和旋转
今天又研究了这个画笔的缩放和旋转,百思不得其解,突然发现画笔最后一个参数是指宽度的单位,会不会是单位不对,缩放不了结果,研究发现,画笔的单位一定要用0也就是通用单位,而非物理单位,这样才能缩放和旋转
放上代码共享之
#include <APIConstants.au3>
#include <WinAPIEx.au3>
#include <GDIPlus.au3>
#include <GDIPlusEx.au3>
#include <GuiSlider.au3>
Global $ScaleX = 5, $ScaleY = 1, $nAngle = 0
GUICreate("第十一讲 GDI+画笔补充缩放旋转", 300, 300)
$nCtrlId = GUICtrlCreatePic("", 0, 0, 300, 200)
$hPicWnd = GUICtrlGetHandle($nCtrlId)
Global $rect
init()
GUIRegisterMsg($WM_HSCROLL, "onHSCROLL")
GUISetState()
update()
While 1
$Msg = GUIGetMsg()
Switch $Msg
Case -3
ExitLoop
EndSwitch
WEnd
GUIDelete()
Exit
Func init()
GUICtrlCreateLabel("水平缩放", 5, 205)
$rect = GUICtrlCreateSlider(60, 205, 100)
GUICtrlSetLimit(-1, 10, 1)
GUICtrlSetData(-1, $ScaleX)
$rect = GUICtrlCreateLabel("", 170, 205, 40, 25)
GUICtrlSetData(-1, $ScaleX)
GUICtrlCreateLabel("垂直绽放", 5, 235)
$rect = GUICtrlCreateSlider(60, 235, 100)
GUICtrlSetLimit(-1, 10, 1)
GUICtrlSetData(-1, $ScaleY)
$rect = GUICtrlCreateLabel("", 170, 235, 40, 25)
GUICtrlSetData(-1, $ScaleY)
GUICtrlCreateLabel("旋转角度", 5, 265)
$rect = GUICtrlCreateSlider(60, 265, 100)
GUICtrlSetLimit(-1, 360, 0)
GUICtrlSetData(-1, $nAngle)
_GUICtrlSlider_SetTicFreq(-1, 60)
$rect = GUICtrlCreateLabel("", 170, 265, 40, 25)
GUICtrlSetData(-1, $nAngle)
EndFunc ;==>init
Func onHSCROLL($hWnd, $iMsg, $wParam, $lParam)
Switch _WinAPI_GetDlgCtrlID($lParam)
Case $rect
$ScaleX = GUICtrlRead($rect)
GUICtrlSetData($rect, $ScaleX)
Case $rect
$ScaleY = GUICtrlRead($rect)
GUICtrlSetData($rect, $ScaleY)
Case $rect
$nAngle = GUICtrlRead($rect)
GUICtrlSetData($rect, $nAngle)
EndSwitch
update()
EndFunc ;==>onHSCROLL
Func update()
Local $HWND_CX = _WinAPI_GetWindowWidth($hPicWnd)
Local $HWND_CY = _WinAPI_GetWindowHeight($hPicWnd)
_GDIPlus_Startup()
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hPicWnd)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics($HWND_CX, $HWND_CY, $hGraphics)
$hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsClear($hBackbuffer, 0xFFECE9D8)
_GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2);光滑模式,2为8*8抗距齿
PenScale($hBackbuffer)
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $HWND_CX, $HWND_CY)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hBackbuffer)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()
EndFunc ;==>update
Func PenScale($hGraphics)
Local $hPen = _GDIPlus_PenCreate(0xFFFF0000, 2, 0);建立画笔,最后一个参数0是指通用单位,只有通用单位才能缩放和旋转,不能用2像素
Local $hBrush = _GDIPlus_LineBrushCreate(0, 0, 20, 20, 0xFFFFFF00, 0xFFFF0000, 1)
Local $hPen2 = _GDIPlus_PenCreate2($hBrush, 2, 0);建立通用单位的渐变画笔
_GDIPlus_BrushDispose($hBrush)
;画笔缩放的旋转
_GDIPlus_PenScaleTransform($hPen, $ScaleX, $ScaleY, 1)
_GDIPlus_PenRotateTransform($hPen, $nAngle, 1)
_GDIPlus_PenScaleTransform($hPen2, $ScaleX, $ScaleY, 1)
_GDIPlus_PenRotateTransform($hPen2, $nAngle, 1)
;绘制矩形和椭圆看效果
_GDIPlus_GraphicsDrawRect($hGraphics, 10, 10, 100, 80, $hPen)
_GDIPlus_GraphicsTranslateTransform($hGraphics, 0, 100)
_GDIPlus_GraphicsDrawEllipse($hGraphics, 10, 10, 100, 80, $hPen)
_GDIPlus_GraphicsResetTransform($hGraphics)
_GDIPlus_GraphicsTranslateTransform($hGraphics, 150, 0)
_GDIPlus_GraphicsDrawRect($hGraphics, 10, 10, 100, 80, $hPen2)
_GDIPlus_GraphicsTranslateTransform($hGraphics, 0, 100)
_GDIPlus_GraphicsDrawEllipse($hGraphics, 10, 10, 100, 80, $hPen2)
;释放画笔
_GDIPlus_PenDispose($hPen)
_GDIPlus_PenDispose($hPen2)
EndFunc ;==>PenScale 回复 1# seniors
大侠,搜索了一篇文章,看看有无参考意义? 回复 2# 楼上风云
pathAddString得到的路径,不是笔划顺序的,我网上也看到过,我认为是假的
因为我用pathAddString后得到子路径,明明不是一笔一笔写的,是一块一块写的,而且不是书写的顺序
如果要笔划顺序的,一定是自己做的库,不应该出现pathAddString这一句 回复 3# seniors
换个角度想,也有可能:
1、用某种方式将所有汉字笔顺以一定规则存储起来,文中就是以二进制方式存储的StrokeInfo.txt,按其具体分析:每个汉字占用816位,总存储20992个汉字,所以最后可以算出文件的大小为(16+100*8)*20992=17129472Bit=2141184Byte=2091KB 也就是2点多M,存储所有的信息占用的空间很小。
2、示例:一个“夏”对应的Unicode码为590F,则直接查找第(590F-4E00)*(16+100*8)位到((590F-4E00)+1)*(16+100*8)-1位即可获得“夏”对应的数据。
3、如果上述方案可行,那么AU3只要实现在指定位置,循环读取并显示指定汉字的笔顺数据即可。 回复 4# 楼上风云
关键是这个StrokeInfo.txt谁去做
总存储20992个汉字的字库,不是说做就做的
程序处理是小事,字库制作是大事 回复 5# seniors
我尝试联系原作者,看能否要到这个TXT,或者部分数据也行,关键是搞清楚它的内容倒底是什么结构。如有结果,会分享出来。 占个座,留个板凳~
页:
[1]