本帖最后由 ccxw1983 于 2014-9-27 00:06 编辑
解决图片处理、显示的3个问题的示例
1.图片拼接;
2.图片缩小;
3.解决窗口最小化后再恢复图片消失不显示的问题。#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
Example()
Func Example()
Local $tmppath = "c:\gmaptmp2"
Local $stype = "baidu"
Local $z = 16
Local $minX = 11582
Local $maxX = 11589
Local $minY = 3340
Local $maxY = 3343
Local $W, $H, $x, $y, $filepath, $blockwidth = 256 / 2
$W = $blockwidth * (Int($maxX) - Int($minX) + 1)
$H = $blockwidth * (Int($maxY) - Int($minY) + 1)
Local $hGUI, $hGraphic
_GDIPlus_Startup()
$hGUI = GUICreate("GDI+", $W, $H)
GUISetState(@SW_SHOW)
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;最终要画的目的
;组装画
Local $BitmapBeOne = _GDIPlus_BitmapCreateFromScan0($W, $H)
;画组装画的画板
Global $hGfxCtxt = _GDIPlus_ImageGetGraphicsContext($BitmapBeOne)
;因为上一步生成的图像句柄背景色是黑色的,需要将背景色填充成白色
_GDIPlus_GraphicsClear($hGfxCtxt, 0xFFFFFFFF)
;在组装画板上画画
For $y = Int($minY) To Int($maxY)
For $x = Int($minX) To Int($maxX)
$filepath = $tmppath & "/" & $stype & "_" & "z" & $z & ",x" & $x & ",y" & $y & ".jpg";
If FileExists($filepath) Then
Local $BitmapImgTmp = _GDIPlus_BitmapCreateFromFile($filepath);一样的 Local $BitmapImgTmp = _GDIPlus_ImageLoadFromFile($filepath);图片大小为256
Local $nX = ($x - $minX) * $blockwidth;x从左到右
Local $nY = 0;谷歌-y上到下;百度-y下到上
If $stype == "baidu" Then
$nY = ($maxY - $y) * $blockwidth
ElseIf $stype == "google" Then
$nY = ($y - $minY) * $blockwidth
EndIf
_GDIPlus_GraphicsDrawImageRect($hGfxCtxt, $BitmapImgTmp, $nX, $nY, $blockwidth, $blockwidth);2.图片缩小(指定画小些就是缩小了);1.图片拼接(按坐标画到一起就是了);
_GDIPlus_ImageDispose($BitmapImgTmp)
;ConsoleWrite($filepath & " 拼凑到 " & " $nX=" & $nX & " $nY=" & $nY & @CRLF)
Else
;ConsoleWrite("not pic: " & $filepath & @CRLF)
EndIf
Next
Next
;组装画贴到最终画板上
_GDIPlus_GraphicsDrawImageRect($hGraphic, $BitmapBeOne, 0, 0, $W, $H)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
_GDIPlus_GraphicsDispose($hGfxCtxt)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_BitmapDispose($BitmapBeOne)
_GDIPlus_Shutdown()
GUIDelete($hGUI)
ExitLoop
Case $GUI_EVENT_RESTORE
;3.解决窗口最小化后再恢复图片消失不显示的问题。
_GDIPlus_GraphicsDrawImageRect($hGraphic, $BitmapBeOne, 0, 0, $W, $H)
EndSwitch
WEnd
EndFunc ;==>Example
|