图片拼接,图片缩小,解决窗口最小化后再恢复图片消失不显示的问题
本帖最后由 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
两个Graphics,一个是窗口目标的,一个是用于组装的,这样可以避免重复做拼接,也可以避免直接画图造成的画面闪烁的问题。 3.3.6.1版本测试缺少_GDIPlus_BitmapCreateFromScan0,刚好我找了下补上。Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0)
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0)
If @error Then Return SetError(@error, @extended, 0)
$GDIP_STATUS = $aResult
Return $aResult
EndFunc ;==>_GDIPlus_BitmapCreateFromScan0 不错的代码,收藏之。 对我有用,多谢分享。 图片拼接,图片缩小 谢谢分享。收藏了 看这源码不错来看看 不错,x'x't'gxxtg 学习一下,可以合理优化。 学习一下,可以合理优化。 最近在学习图片处理,收藏了,谢谢分享!
页:
[1]