找回密码
 加入
搜索
查看: 6310|回复: 10

[图形处理] [已解决](高手在哪里)打开一张图片,如何用鼠标在图片上绘制一条直线控件

[复制链接]
发表于 2014-9-24 22:40:21 | 显示全部楼层 |阅读模式
本帖最后由 krgocn 于 2014-9-28 03:50 编辑

我想打开一张图片,然后用鼠标绘制一条直线。
可以用鼠标调整长度。
类似WORD中的插入直线。
 楼主| 发表于 2014-9-26 22:46:59 | 显示全部楼层
没人帮我
发表于 2014-9-27 01:14:04 | 显示全部楼层
不是有现成的吗
 楼主| 发表于 2014-9-27 03:55:17 | 显示全部楼层
回复 3# netegg


我找了好长时间,一直没找到。麻烦指点一下
 楼主| 发表于 2014-9-27 03:57:45 | 显示全部楼层
回复 3# netegg


我打算做一个图片内物品尺寸测量的软件。
现在就差用鼠标修改直线的长度了。
发表于 2014-9-27 16:35:36 | 显示全部楼层
本帖最后由 netegg 于 2014-9-27 16:36 编辑

回复 5#
http://www.autoitscript.com/forum/topic/88637-simple-image-resizer/?hl=gdi#entry666475
发表于 2014-9-27 17:08:40 | 显示全部楼层
发表于 2014-9-27 17:30:56 | 显示全部楼层
本帖最后由 netegg 于 2014-9-27 17:50 编辑

[au3]#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[4] = _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[6]
    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[/au3]
发表于 2014-9-27 17:35:13 | 显示全部楼层
修改图片尺寸和图像控件的宽高,图像就变了
发表于 2014-9-27 17:37:43 | 显示全部楼层
想画直线附加一层
 楼主| 发表于 2014-9-28 05:47:35 | 显示全部楼层
回复 8# netegg


   太感谢你了
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-19 14:50 , Processed in 0.077703 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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