Jump to content

how to capture irregular picture?


Recommended Posts

Normally, the function of _ScreenCapture_Capture() can capture rectangle image. But how to capture polygon image?

I know rectangle image can be changed to polygon image through transparent color. but how to?

Please give a example.

Link to comment
Share on other sites

Lots of capturing software(Such as PicPick, FSCapture) have one functionality, so-called FREEHAND capture. You can move mouse to get irregular orbit. Then they can capture a picture through the orbit.

If using au3, how to realize this functionality?

Link to comment
Share on other sites

soo. let me explain what i get from this...

You capture a non Rectangular image from the screen.

The capture image is always a rectangle, so what you want is that the part of the image where is not the shape you want to capture, set to tranparent.

For ex.Posted Image

The black part represents what you want to capture, the grey part represents tranparent areas.

Link to comment
Share on other sites

soo. let me explain what i get from this...

You capture a non Rectangular image from the screen.

The capture image is always a rectangle, so what you want is that the part of the image where is not the shape you want to capture, set to tranparent.

For ex.Posted Image

The black part represents what you want to capture, the grey part represents tranparent areas.

Yeah, I have known the principle it's just like you said. But I want to know how to realize it through GDI+

Link to comment
Share on other sites

Sorry i ask for me... because i never do something like this...

so The problem is to recognizing the shape

Is this for a window?

for current screen.

like following record(It's very cool)

Edited by happytc
Link to comment
Share on other sites

Try this (it is a fast hack!):

;code by UEZ 2011
#AutoIt3Wrapper_UseX64=n
#include <Misc.au3>
#include <ScreenCapture.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)



_GDIPlus_Startup()
$hHBitmap = _ScreenCapture_Capture("", 0, 0, @DesktopWidth, @DesktopHeight, False)
$hTexture = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap)
$hTextureBrush = _GDIPlus_TextureCreate($hTexture)
_WinAPI_DeleteObject($hHBitmap)

$hGUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOPMOST)
GUISetState()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsDrawImage($hGraphic, $hTexture, 0, 0)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
$hPen = _GDIPlus_PenCreate(0xFFFF0000, 2)

Global $dll = DllOpen("user32.dll")

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

$exitloop = False
$min_x = @DesktopWidth
$min_y = @DesktopHeight
$max_x = 0
$max_y = 0
$mo = MouseGetCursor()
Global $aPoints[2^20][2]
$p = 1
GUISetCursor(14, 1, $hGUI)
While Sleep(100)
    $mxo = MouseGetPos(0)
    $myo = MouseGetPos(1)
    While _IsPressed("01", $dll) * Sleep(10)
        $mx = MouseGetPos(0)
        $my = MouseGetPos(1)
        _GDIPlus_GraphicsDrawLine($hGraphic, $mx, $my, $mxo, $myo, $hPen)
        $mxo = $mx
        $myo = $my
        $aPoints[$p][0] = $mx
        $aPoints[$p][1] = $my
        $min_x = Min($min_x, $mx)
        $min_y = Min($min_y, $my)
        $max_x = Max($max_x, $mx)
        $max_y = Max($max_y, $my)
        $p += 1
        $exitloop = True
    WEnd
    If $exitloop Then ExitLoop
WEnd
GUISetCursor($mo, 1, $hGUI)

ReDim $aPoints[$p][2]
$aPoints[0][0] = $p - 1

_GDIPlus_GraphicsDispose($hGraphic)
$new_w =  $max_x - $min_x
$new_h =  $max_y - $min_y
$hBitmap_Hidden = _GDIPlus_BitmapCreateFromScan0(@DesktopWidth, @DesktopHeight)
$hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap_Hidden)
_GDIPlus_GraphicsClear($hContext, 0xFFFFFFFF)

_GDIPlus_GraphicsFillPolygon($hContext, $aPoints, $hTextureBrush)
$hBitmap_Capture = _GDIPlus_BitmapCloneArea($hBitmap_Hidden, $min_x, $min_y, $new_w, $new_h)
;~ _GDIPlus_ImageSaveToFile($hBitmap_Capture, "Testc.jpg")

GUISetOnEvent(-3, "")
GUIDelete($hGUI)
$hGUI = GUICreate("Freehand Screen Capture by UEZ 2011", $new_w, $new_h)
GUISetState()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap_Capture, 0, 0)

GUISetOnEvent(-3, "_Exit")

_GDIPlus_BitmapDispose($hBitmap_Hidden)
_GDIPlus_BitmapDispose($hBitmap_Capture)
_GDIPlus_GraphicsDispose($hContext)

While Sleep(5000)
WEnd

Func Max($a, $b)
    If $a > $b Then Return $a
    Return $b
EndFunc

Func Min($a, $b)
    If $a < $b Then Return $a
    Return $b
EndFunc

Func _Exit()
    DllClose($dll)
    _GDIPlus_BrushDispose($hTextureBrush)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_BitmapDispose($hTexture)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
    $aPoints = 0
    Exit
EndFunc

Hold down lmb and draw something to the screen. Release lmb to capture the polygone area.

Br,

UEZ

PS: no Voodoo needed :mellow:

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

  • 6 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...