[已解决](高手在哪里)打开一张图片,如何用鼠标在图片上绘制一条直线控件
本帖最后由 krgocn 于 2014-9-28 03:50 编辑我想打开一张图片,然后用鼠标绘制一条直线。
可以用鼠标调整长度。
类似WORD中的插入直线。 没人帮我{:face (319):} 不是有现成的吗 回复 3# netegg
我找了好长时间,一直没找到。麻烦指点一下 回复 3# netegg
我打算做一个图片内物品尺寸测量的软件。
现在就差用鼠标修改直线的长度了。 本帖最后由 netegg 于 2014-9-27 16:36 编辑
回复 5#
http://www.autoitscript.com/forum/topic/88637-simple-image-resizer/?hl=gdi#entry666475 http://colonelpanic.net/2010/11/resizing-an-image-with-gdi-with-cpp/ 本帖最后由 netegg 于 2014-9-27 17:50 编辑
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
;#Include <GDIPlusEx.au3>
Global Const $STM_SETIMAGE = 0x0172
_GDIPlus_Startup()
$hBitmap = _GDIPlus_ScaleImage2(@ScriptDir & "\Torus.png", 50, 30)
$hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
_GDIPlus_BitmapDispose($hBitmap)
$Form = GUICreate("Test", 600, 400)
Global $Pic = GUICtrlCreatePic("", 50, 40, 50, 30, -1, $WS_EX_CLIENTEDGE)
$hB = GUICtrlSendMsg($Pic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap)
If $hB Then _WinAPI_DeleteObject($hB)
GUISetState(@SW_SHOW,$Form)
;$cForm = GUICreate("Test", 100, 100,1,1,$WS_SizeBox)
; _WinAPI_SetParent($cForm,GUICtrlGetHandle($Pic))
;GUISetState(@SW_SHOW,$cForm)
;~ GUIRegisterMsg($WM_MOVE, "_WM_MOVE_SIZE")
;~ GUIRegisterMsg($WM_SIZE, "_WM_MOVE_SIZE")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
_WinAPI_DeleteObject($hHBitmap)
_GDIPlus_Shutdown()
Exit
EndSwitch
WEnd
Func _WM_MOVE_SIZE($hWnd, $Msg, $wParam, $lParam)
$hB = GUICtrlSendMsg($Pic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $hB = ' & $hB & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
If $hB Then _WinAPI_DeleteObject($hB)
EndFunc
Func _GDIPlus_ScaleImage2($sFile, $iNewWidth, $iNewHeight, $iBGColor = 0xFFF0F0F0, $bBGClear = True, $iInterpolationMode = 7) ;coded by UEZ 2012
If Not FileExists($sFile) Then Return SetError(1, 0, 0)
Local $hImage = _GDIPlus_ImageLoadFromFile($sFile)
If @error Then Return SetError(2, 0, 0)
Local $iWidth = _GDIPlus_ImageGetWidth($hImage)
Local $iHeight = _GDIPlus_ImageGetHeight($hImage)
;local $aArray = _GDIPlus_ImageGetBounds($hImage)
Local $iW, $iH, $f, $fRatio
If $iWidth > $iHeight Then
$f = $iWidth / $iNewWidth
Else
$f = $iHeight / $iNewHeight
EndIf
$iW = Int($iWidth / $f)
$iH = Int($iHeight / $f)
If $iW > $iNewWidth Then
$fRatio = $iNewWidth / $iW
$iW = Int($iW * $fRatio)
$iH = Int($iH * $fRatio)
ElseIf $iH > $iNewHeight Then
$fRatio = $iNewHeight / $iH
$iW = Int($iW * $fRatio)
$iH = Int($iH * $fRatio)
EndIf
Local $hBitmap = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iW, "int", $iH, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0)
If @error Then Return SetError(3, 0, 0)
$hBitmap = $hBitmap
Local $hBmpCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
If $bBGClear Then _GDIPlus_GraphicsClear($hBmpCtxt, $iBGColor)
DllCall($ghGDIPDll, "uint", "GdipSetInterpolationMode", "handle", $hBmpCtxt, "int", $iInterpolationMode)
_GDIPlus_GraphicsDrawImageRect($hBmpCtxt, $hImage, 0, 0, $iW, $iH)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_GraphicsDispose($hBmpCtxt)
Return $hBitmap
EndFunc 修改图片尺寸和图像控件的宽高,图像就变了 想画直线附加一层 回复 8# netegg
太感谢你了
页:
[1]