Jump to content
Sign in to follow this  
happytc

how to capture irregular picture?

Recommended Posts

happytc

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.

Share this post


Link to post
Share on other sites
monoscout999

I don`t get it well..

you capture the rectangle where the polygon is.

Share this post


Link to post
Share on other sites
happytc

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?

Share this post


Link to post
Share on other sites
happytc

GDI voodoo.

I also knew using GDI+ could realize it.

But how to?

Share this post


Link to post
Share on other sites
monoscout999

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.

Share this post


Link to post
Share on other sites
happytc

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+

Share this post


Link to post
Share on other sites
monoscout999

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?

Edited by monoscout999

Share this post


Link to post
Share on other sites
happytc

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

Share this post


Link to post
Share on other sites
UEZ

Try this (it is a fast hack!):

;code by UEZ 2011
#include <Array.au3>
#include <Misc.au3>
#include <ScreenCapture.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)

_GDIPlus_Startup()
$hHBitmap = _ScreenCapture_Capture("", 0, 0, @DesktopWidth, @DesktopHeight, False)
$hTexture = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap)
$hTextureBrush = DllCall($ghGDIPDll, "uint", "GdipCreateTexture", "hwnd", $hTexture, "int", 0, "int*", 0)
$hTextureBrush  = $hTextureBrush [3]
_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(-3, "_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 = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", @DesktopWidth, "int", @DesktopHeight, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0)
$hBitmap_Hidden = $hBitmap_Hidden[6]
$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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.