本帖最后由 298311657 于 2015-12-28 19:34 编辑
九宫切图,懂的就看看,不懂的就百度吧,今天不想打字,看图看效果
这是用到的图片
代码:(代码在以下环境允许正常:操作系统:WIN_7/Service Pack 1 CPU:X64 系统架构:X64 环境(语言:0804) Autoit:3.3.14.2。其它环境未测试,不保证效果)
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <SendMessage.au3>
#include <GDIPlus.au3>
GUICreate("九宫切图简例", 700, 330)
Local $idPic = GUICtrlCreatePic("", 5, 5, 340, 290)
_GDIPlus_Startup()
_JGDraw("bk.jpg", $idPic, 340, 290, 3)
_GDIPlus_Shutdown()
GUICtrlCreateLabel("使用九宫切图的效果", 5, 300, 340, 18)
GUICtrlCreatePic("bk.jpg", 355, 5, 340, 290)
GUICtrlCreateLabel("未使用九宫切图的效果", 355, 300, 340, 18)
GUISetState(@SW_SHOW)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
GUIDelete()
;九宫格切图
Func _JGDraw($sFile, $hwnd, $iWidth, $iHeight, $iLWidth = 0)
Local $hImage = _GDIPlus_ImageLoadFromFile($sFile)
Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight)
Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap);画布
Local $rect = DllStructCreate("struct;int X;int Y;int Width;int Height;endstruct")
$rect.X = 0
$rect.Y = 0
$rect.Width = $iWidth
$rect.Height = $iHeight
Local $iImgW = _GDIPlus_ImageGetWidth($hImage)
Local $iImgH = _GDIPlus_ImageGetHeight($hImage)
;左上、右上、左下、右下 四角
_GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hImage, $rect.X, $rect.Y, $iLWidth, $iLWidth, 0, 0, $iLWidth, $iLWidth)
_GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hImage, $iImgW - $iLWidth, 0, $iLWidth, $iLWidth, $rect.Width - $iLWidth, $rect.Y, $iLWidth, $iLWidth)
_GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hImage, 0, $iImgH - $iLWidth, $iLWidth, $iLWidth, $rect.X, $rect.Height - $iLWidth, $iLWidth, $iLWidth)
_GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hImage, $iImgW - $iLWidth, $iImgH - $iLWidth, $iLWidth, $iLWidth, $rect.Width - $iLWidth, $rect.Height - $iLWidth, $iLWidth, $iLWidth)
;左、上、右、下 四边
_GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hImage, 0, $iLWidth, $iLWidth, $iImgH - 2*$iLWidth, $rect.X, $rect.Y + $iLWidth, $iLWidth, $rect.Height - 2*$iLWidth)
_GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hImage, $iLWidth, 0, $iImgW - 2*$iLWidth, $iLWidth, $rect.X + $iLWidth, $rect.Y, $rect.Width - 2*$iLWidth, $iLWidth)
_GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hImage, $iImgW - $iLWidth, $iLWidth, $iLWidth, $iImgH - 2*$iLWidth, $rect.Width - $iLWidth, $rect.Y + $iLWidth, $iLWidth, $rect.Height - 2*$iLWidth)
_GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hImage, $iLWidth, $iImgH - $iLWidth, $iImgW - 2*$iLWidth, $iLWidth, $rect.X + $iLWidth, $rect.Height - $iLWidth, $rect.Width - 2*$iLWidth, $iLWidth)
;中间
_GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hImage, $iLWidth, $iLWidth, $iImgW - 2*$iLWidth, $iImgH - 2*$iLWidth, $rect.X + $iLWidth, $rect.Y + $iLWidth, $rect.Width - 2*$iLWidth, $rect.Height - 2*$iLWidth)
Local $hBit = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_ImageDispose($hImage)
If Not IsHWnd($hwnd) Then $hwnd = GUICtrlGetHandle($hwnd)
Local $hPrev = _SendMessage($hwnd, 370, 0, $hBit);$STM_SETIMAGE=370, $IMAGE_BITMAP=0
_WinAPI_DeleteObject($hBit)
EndFunc
|