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

[原创] 图片拼接,图片缩小,解决窗口最小化后再恢复图片消失不显示的问题

  [复制链接]
发表于 2014-9-27 00:03:59 | 显示全部楼层 |阅读模式
本帖最后由 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

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×

评分

参与人数 1金钱 +30 收起 理由
lpxx + 30

查看全部评分

 楼主| 发表于 2014-9-27 00:08:27 | 显示全部楼层
两个Graphics,一个是窗口目标的,一个是用于组装的,这样可以避免重复做拼接,也可以避免直接画图造成的画面闪烁的问题。
发表于 2014-9-27 08:02:25 | 显示全部楼层
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[0]
        Return $aResult[6]
EndFunc   ;==>_GDIPlus_BitmapCreateFromScan0
发表于 2014-9-27 16:07:34 | 显示全部楼层
不错的代码,收藏之。
发表于 2014-10-30 18:18:15 | 显示全部楼层
对我有用,多谢分享。
发表于 2014-11-5 23:19:13 | 显示全部楼层
图片拼接,图片缩小
发表于 2016-4-28 20:54:20 | 显示全部楼层
谢谢分享。收藏了
发表于 2017-1-14 07:06:22 | 显示全部楼层
看这源码不错来看看
发表于 2017-12-31 16:10:48 | 显示全部楼层
不错,x'x't'gxxtg
发表于 2020-9-25 10:52:12 | 显示全部楼层
学习一下,可以合理优化。
发表于 2020-9-25 10:52:28 | 显示全部楼层
学习一下,可以合理优化。
发表于 2020-11-17 14:38:06 | 显示全部楼层
最近在学习图片处理,收藏了,谢谢分享!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-24 11:29 , Processed in 0.085936 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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