Sign in to follow this  
Followers 0
HardCopy

Drawing Pixels / Retains Previous Pixel Contents

12 posts in this topic

Hi

Can someone please look at this scratch code & explain why it does not function as i am expecting.

Probably something i am missing...

Using the Current Beta:

It scans the top left corner of your screen & draws what it sees onto a gui in a 100x100 Graphic Control.

However if you move another window or something into the scan zone, the previous screen contents are shown aswell, not just what is there now.

Run this example and you will see what i mean.

Thx for reading

Regards

HardCopy

#include <GUIConstants.au3>

$MyGui = GUICreate(" My GUI")

$g1 = GUICtrlCreateGraphic(20, 50, 200, 200)
GUICtrlSetColor($g1, 3763621)

GUISetState()

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    _CopyArea()
    Sleep(5)
WEnd


Func _CopyArea()
    $x1 = 10
    $y1 = 10
    For $i = $x1 to $x1+100
        for $j = $y1 To $y1+100
            $PixColour = PixelGetColor($i,$j)
            GUICtrlSetGraphic($g1, $GUI_GR_COLOR, $PixColour)
            GUICtrlSetGraphic($g1, $GUI_GR_PIXEL, $i,$j)
        Next
    Next
    GUICtrlSetGraphic($g1, $GUI_GR_REFRESH)
EndFunc  ;==>_CopyArea

Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad

Share this post


Link to post
Share on other sites



The only way I could get it not to show the previous drawn image was with GUICtrlDelete() before the function call. And put $g1 = GUICtrlCreateGraphic(20, 50, 200, 200) in the function, but that looked really bad.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

The only way I could get it not to show the previous drawn image was with GUICtrlDelete() before the function call. And put $g1 = GUICtrlCreateGraphic(20, 50, 200, 200) in the function, but that looked really bad.

Thx for taking a look smoke.

I concluded the same workaround , but it kinda limits the useability.

I wonder if this is a bug or feature!. Dont want to post as bug just yet, as I have only just started

playing with drawing functions, and dont trust my understanding of the drawing options.

Maybe JPM or Gary can enlighten me.

HardCopy


Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Well, I have just seen the Function SetPixel - by Layer

Used that, seems to work as expected , but a little slow.

Only problem now, seems the colours are not set correctly. *** Fixed

HardCopy

#include <GUIConstants.au3>
$MyGui = GUICreate(" My GUI")
Opt("ColorMode",1)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
    _CopyArea()
    Sleep(5)
WEnd


Func _CopyArea()
    $x1 = 10
    $y1 = 10
    For $i = $x1 To $x1 + 100
        For $j = $y1 To $y1 + 100
            $PixColour = PixelGetColor($i, $j)
            SetPixel($MyGui, $i, $j, "0x" & hex($PixColour,6))
        Next
    Next
EndFunc ;==>_CopyArea


Func SetPixel($handle, $x, $y, $color);;; From Forum / Layers SetPixel Func
    $dc = DllCall("user32.dll", "int", "GetDC", "hwnd", $handle)
    $setpixel = DllCall("gdi32.dll", "long", "SetPixel", "long", $dc[0], "long", $x, "long", $y, "long", $color)
    $realesedc = DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "int", $dc[0])
EndFunc ;==>SetPixel
Edited by HardCopy

Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

The colors used in the set pixel dll call are in the following format...

0x00BBGGRR where B=blue, G=green, and R=red

Hope that helps you out.

Thanks Onoitsu2, resolves the colour problem

1 down, 1 to go

**Updated Second Example - Now works as expected

HardCopy

Edited by HardCopy

Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad

Share this post


Link to post
Share on other sites

Thanks Onoitsu2, resolves the colour problem

1 down, 1 to go

**Updated Second Example - Now works as expected

HardCopy

I played with that too!!!! Before I posted.

I thought it was way to slow for what you wanted because you were doing a Sleep(5).

Personally, what I would do HC is ask lazycat if there was anyway to set a region to the his screen capture dll. If so, that would be much quicker until someone could explain how or why this behavior is happening.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

How about this?

#include <GUIConstants.au3>
$MyGui = GUICreate(" My GUI")
Global $SRCCOPY = 0x00CC0020
GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
    _CopyArea()
    Sleep(5)
WEnd


Func _CopyArea()
    $x1 = 10
    $y1 = 10
    $DeskHDC = DLLCall("user32.dll","int","GetDC","hwnd",0)
    $GUIHDC = DLLCall("user32.dll","int","GetDC","hwnd",$MyGui)
    If Not @error Then
        DLLCall("gdi32.dll", "int", "StretchBlt", "int", $GUIHDC[0], "int", _
            10, "int", 10, "int", 100, "int", 100, "int", $DeskHDC[0], "int", _
            $x1, "int", $y1, "int", 100 ,"int", 100, _
            "long", $SRCCOPY)
        DLLCall("user32.dll","int","ReleaseDC","int",$DeskHDC[0],"hwnd",0)
        DLLCall("user32.dll","int","ReleaseDC","int",$GUIHDC[0],"hwnd",$MyGui)
    EndIf
EndFunc;==>_CopyArea

I used StretchBlt because I just borrowed it from my magnification script. I think BitBlt is better for copying, but StretchBlt lets you do stuff with the copy (make it bigger or smaller, etc).

Either way, they're much quicker than pixel-by-pixel copies.

Share this post


Link to post
Share on other sites

How about this?

Wow GreenMachine, this flies.

Very Nice indeed, Thanks for the code.

Ive got to dig into this DLL stuff. Any good pointers GreenMachine?

Regards

HardCopy

ps

Still be interested to know why my initial code fails.


Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad

Share this post


Link to post
Share on other sites

Well...

I've gotten a lot of information about DLLs from the forums - Larry tends to do a lot of interesting things with DllCalls, and then I always go to the MSDN library and start looking up all the functions he uses and the ones that are similar to them.

In addition, there's a handy program - DLL Export Viewer - that lists all the exported DLL functions and where they came from. You can use that to see a list of functions, and then look up the ones that sound interesting. That's how I found a lot of the functions.

http://www.nirsoft.net/utils/dll_export_viewer.html

Share this post


Link to post
Share on other sites

#11 ·  Posted

Nice one greenmachine!

I played with it a bit, works really well.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#12 ·  Posted

Wow GreenMachine, this flies.

Very Nice indeed, Thanks for the code.

Ive got to dig into this DLL stuff. Any good pointers GreenMachine?

Regards

HardCopy

ps

Still be interested to know why my initial code fails.

This has functions for the DGI calls http://www.autoitscript.com/fileman/users/outeast/files/gdi32.au3

I keep meaning to have a play with these when I have some time! :think:

Another good one is this Media UDF http://www.autoitscript.com/forum/index.ph...32&hl=Media+UDF


2015 - Still no flying cars, instead blankets with sleeves.

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  
Followers 0