Jump to content
Sign in to follow this  
gruntydatsun

Blur or Blackout a Section of the Screen

Recommended Posts

I tried the script on which looked promising but I get an error complaining about

C:\Scripts\GDI\GDI_001.au3(33,75) : WARNING: $RDW_INVALIDATE: possibly used before declaration.

The script from that page is below (not my code):

#include <GUIConstants.au3>
#Include <ScreenCapture.au3>
#include <GDIPlus.au3>
$hGUI = GUICreate("Blurp", 200,120)
GUICtrlCreateLabel("InterpolationMode", 20, 20, 100, 20)
GUICtrlCreateLabel("Stretch ratio", 20, 50, 100, 20)
$cInputIM = GUICtrlCreateInput("6", 120, 15, 50, 20)
GUICtrlSetTip(-1, "Possible values" & @CRLF & "0 - 7")
$cInputSR = GUICtrlCreateInput("1.25", 120, 45, 50, 20)
GUICtrlSetTip(-1, "Possible values" & @CRLF & "1.0 - @DesktopHeight.0")
$cBtnBlur = GUICtrlCreateButton("Blur", 20, 80, 80, 20)
$cBtnClear = GUICtrlCreateButton("Clear", 100, 80, 80, 20)
GUISetState()
_GDIPlus_Startup()
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _GDIPlus_Shutdown()
            Exit
        Case $cBtnBlur
            _ScreenBlur(GUICtrlRead($cInputSR), GUICtrlRead($cInputIM))
        Case $cBtnClear
            _ScreenClear()
    EndSwitch
WEnd
Func _ScreenClear()
    _WinAPI_RedrawWindow(_WinAPI_GetDesktopWindow(), 0, 0, $RDW_INVALIDATE+$RDW_UPDATENOW+$RDW_ALLCHILDREN)
EndFunc
Func _ScreenBlur($nRatio, $iInterMode, $iSmoothMode=0, $iPixOffsetMode = 2)
  
    $hBMP = _ScreenCapture_Capture("", 0,0,-1,-1, False)
    $hImg = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)
    $hScreenDC = _WinAPI_GetDC(0)
    $hScreenGraph = _GDIPlus_GraphicsCreateFromHDC($hScreenDC)
  
    $hImg2 = _GDIPlus_BitmapCloneArea($hImg, 0, 0, @DesktopWidth/$nRatio, @DesktopHeight/$nRatio)
    $hMemGraph = _GDIPlus_ImageGetGraphicsContext($hImg2)
;http://msdn2.microsoft.com/en-us/library/ms534141(VS.85).aspx
;InterpolationModeDefault = 0
;InterpolationModeLowQuality = 1
;InterpolationModeHighQuality = 2
;InterpolationModeBilinear = 3
;InterpolationModeBicubic = 4
;InterpolationModeNearestNeighbor = 5
;InterpolationModeHighQualityBilinear = 6
;InterpolationModeHighQualityBicubic = 7
    $a = DllCall("GDIPlus.dll", "int", "GdipSetInterpolationMode", "hwnd", $hMemGraph, "int", $iInterMode)
    $a = DllCall("GDIPlus.dll", "int", "GdipSetInterpolationMode", "hwnd", $hScreenGraph, "int", $iInterMode)
;http://msdn2.microsoft.com/en-us/library/ms534169(VS.85).aspx
;PixelOffsetModeDefault = 0 = PixelOffsetModeNone
;PixelOffsetModeHighSpeed = 1 = PixelOffsetModeNone
;PixelOffsetModeHighQuality = 2 = PixelOffsetModeHalf
;PixelOffsetModeNone = 3
;PixelOffsetModeHalf = 4
    $a = DllCall("GDIPlus.dll", "int", "GdipSetPixelOffsetMode", "hwnd", $hMemGraph, "int", $iPixOffsetMode)
    $a = DllCall("GDIPlus.dll", "int", "GdipSetPixelOffsetMode", "hwnd", $hScreenGraph, "int", $iPixOffsetMode)
;http://msdn2.microsoft.com/en-us/library/ms534173(VS.85).aspx
;SmoothingModeDefault = 0 = SmoothingModeNone
;SmoothingModeHighSpeed = 1 = SmoothingModeNone
;SmoothingModeHighQuality = 2 = SmoothingModeAntiAlias8x4
;SmoothingModeNone
;SmoothingModeAntiAlias8x4
;SmoothingModeAntiAlias = SmoothingModeAntiAlias8x4
;SmoothingModeAntiAlias8x8
    $a = DllCall("GDIPlus.dll", "int", "GdipSetSmoothingMode", "hwnd", $hMemGraph, "int", $iSmoothMode)
    $a = DllCall("GDIPlus.dll", "int", "GdipSetSmoothingMode", "hwnd", $hScreenGraph, "int", $iSmoothMode)
    _GDIPlus_GraphicsDrawImageRectRect($hMemGraph, $hImg, 0, 0, @DesktopWidth, @DesktopHeight, 0, 0, @DesktopWidth/$nRatio, @DesktopHeight/$nRatio)
    _GDIPlus_GraphicsDrawImageRectRect($hScreenGraph, $hImg2, 0, 0, @DesktopWidth/$nRatio, @DesktopHeight/$nRatio, 0, 0, @DesktopWidth, @DesktopHeight)
  
    _WinAPI_DeleteObject($hBMP)
    _GDIPlus_ImageDispose($hImg)
    _GDIPlus_ImageDispose($hImg2)
    _GDIPlus_GraphicsDispose($hMemGraph)
    _GDIPlus_GraphicsDispose($hScreenGraph)
    _WinAPI_ReleaseDC(0, $hScreenDC)
EndFunc

Does anyone know what to include to get these variables?

Edited by gruntydatsun

Share this post


Link to post
Share on other sites

Replace #include <GDIPlus.au3> with #include <WindowsConstants.au3> and it should work properly.

Br,

UEZ

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

Thanks UEZ, this one is working now.

#include <GUIConstants.au3>
#include <Constants.au3>
#Include <ScreenCapture.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
$hGUI = GUICreate("Blurp", 200,120)
GUICtrlCreateLabel("InterpolationMode", 20, 20, 100, 20)
GUICtrlCreateLabel("Stretch ratio", 20, 50, 100, 20)
$cInputIM = GUICtrlCreateInput("6", 120, 15, 50, 20)
GUICtrlSetTip(-1, "Possible values" & @CRLF & "0 - 7")
$cInputSR = GUICtrlCreateInput("1.25", 120, 45, 50, 20)
GUICtrlSetTip(-1, "Possible values" & @CRLF & "1.0 - @DesktopHeight.0")
$cBtnBlur = GUICtrlCreateButton("Blur", 20, 80, 80, 20)
$cBtnClear = GUICtrlCreateButton("Clear", 100, 80, 80, 20)
GUISetState()
_GDIPlus_Startup()
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _GDIPlus_Shutdown()
            Exit
        Case $cBtnBlur
            _ScreenBlur(GUICtrlRead($cInputSR), GUICtrlRead($cInputIM))
        Case $cBtnClear
            _ScreenClear()
    EndSwitch
WEnd
Func _ScreenClear()
    _WinAPI_RedrawWindow(_WinAPI_GetDesktopWindow(), 0, 0, $RDW_INVALIDATE+$RDW_UPDATENOW+$RDW_ALLCHILDREN)
EndFunc
Func _ScreenBlur($nRatio, $iInterMode, $iSmoothMode=0, $iPixOffsetMode = 2)
    $hBMP = _ScreenCapture_Capture("", 0,0,-1,-1, False)
    $hImg = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)
    $hScreenDC = _WinAPI_GetDC(0)
    $hScreenGraph = _GDIPlus_GraphicsCreateFromHDC($hScreenDC)
    $hImg2 = _GDIPlus_BitmapCloneArea($hImg, 0, 0, @DesktopWidth/$nRatio, @DesktopHeight/$nRatio)
    $hMemGraph = _GDIPlus_ImageGetGraphicsContext($hImg2)
;http://msdn2.microsoft.com/en-us/library/ms534141(VS.85).aspx
;InterpolationModeDefault = 0
;InterpolationModeLowQuality = 1
;InterpolationModeHighQuality = 2
;InterpolationModeBilinear = 3
;InterpolationModeBicubic = 4
;InterpolationModeNearestNeighbor = 5
;InterpolationModeHighQualityBilinear = 6
;InterpolationModeHighQualityBicubic = 7
    $a = DllCall("GDIPlus.dll", "int", "GdipSetInterpolationMode", "hwnd", $hMemGraph, "int", $iInterMode)
    $a = DllCall("GDIPlus.dll", "int", "GdipSetInterpolationMode", "hwnd", $hScreenGraph, "int", $iInterMode)
;http://msdn2.microsoft.com/en-us/library/ms534169(VS.85).aspx
;PixelOffsetModeDefault = 0 = PixelOffsetModeNone
;PixelOffsetModeHighSpeed = 1 = PixelOffsetModeNone
;PixelOffsetModeHighQuality = 2 = PixelOffsetModeHalf
;PixelOffsetModeNone = 3
;PixelOffsetModeHalf = 4
    $a = DllCall("GDIPlus.dll", "int", "GdipSetPixelOffsetMode", "hwnd", $hMemGraph, "int", $iPixOffsetMode)
    $a = DllCall("GDIPlus.dll", "int", "GdipSetPixelOffsetMode", "hwnd", $hScreenGraph, "int", $iPixOffsetMode)
;http://msdn2.microsoft.com/en-us/library/ms534173(VS.85).aspx
;SmoothingModeDefault = 0 = SmoothingModeNone
;SmoothingModeHighSpeed = 1 = SmoothingModeNone
;SmoothingModeHighQuality = 2 = SmoothingModeAntiAlias8x4
;SmoothingModeNone
;SmoothingModeAntiAlias8x4
;SmoothingModeAntiAlias = SmoothingModeAntiAlias8x4
;SmoothingModeAntiAlias8x8
    $a = DllCall("GDIPlus.dll", "int", "GdipSetSmoothingMode", "hwnd", $hMemGraph, "int", $iSmoothMode)
    $a = DllCall("GDIPlus.dll", "int", "GdipSetSmoothingMode", "hwnd", $hScreenGraph, "int", $iSmoothMode)
    _GDIPlus_GraphicsDrawImageRectRect($hMemGraph, $hImg, 0, 0, @DesktopWidth, @DesktopHeight, 0, 0, @DesktopWidth/$nRatio, @DesktopHeight/$nRatio)
    _GDIPlus_GraphicsDrawImageRectRect($hScreenGraph, $hImg2, 0, 0, @DesktopWidth/$nRatio, @DesktopHeight/$nRatio, 0, 0, @DesktopWidth, @DesktopHeight)
    _WinAPI_DeleteObject($hBMP)
    _GDIPlus_ImageDispose($hImg)
    _GDIPlus_ImageDispose($hImg2)
    _GDIPlus_GraphicsDispose($hMemGraph)
    _GDIPlus_GraphicsDispose($hScreenGraph)
    _WinAPI_ReleaseDC(0, $hScreenDC)
EndFunc

When you hit the clear button it calls

Func _ScreenClear()
    _WinAPI_RedrawWindow(_WinAPI_GetDesktopWindow(), 0, 0, $RDW_INVALIDATE+$RDW_UPDATENOW+$RDW_ALLCHILDREN)
EndFunc

but this doesn't unblurr the screen for some reason. Only if I terminate the program and it calls _GDIPlus_Shutdown() does the blurr effect go away.

I've considered what I' trying to achieve here and blurring is not sufficient to hide the onscreen keyboard strokes.

What I really need to to is just draw a black rectangle over an area of the screen. Sorry to be such a pita.

Share this post


Link to post
Share on other sites

I tried to modify this code to blur just a rectangle with top left at 30,420 and bottom right at 610.660.

It's not working. Can anyone see what I'm doing wrong here?

#include <GUIConstants.au3>
#include <Constants.au3>
#Include <ScreenCapture.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
HotKeySet("+!d", "_ScreenBlur")  ;Shift-Alt-d
 
;top left of target area 30,420
;bottom right of target area 610.660
while 1
Sleep(1000)
WEnd
Func _ScreenBlur()
_GDIPlus_Startup()
$nRatio = 50
$iInterMode = 1
$iPixOffsetMode = 2
$iSmoothMode=0
    $hBMP = _ScreenCapture_Capture("",30,420,610,660, False)
    $hImg = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)
    $hScreenDC = _WinAPI_GetDC(0)
    $hScreenGraph = _GDIPlus_GraphicsCreateFromHDC($hScreenDC)
    $hImg2 = _GDIPlus_BitmapCloneArea($hImg, 30, 420, 580/$nRatio, 240/$nRatio)
    $hMemGraph = _GDIPlus_ImageGetGraphicsContext($hImg2)
    $a = DllCall("GDIPlus.dll", "int", "GdipSetInterpolationMode", "hwnd", $hMemGraph, "int", $iInterMode)
    $a = DllCall("GDIPlus.dll", "int", "GdipSetInterpolationMode", "hwnd", $hScreenGraph, "int", $iInterMode)
    $a = DllCall("GDIPlus.dll", "int", "GdipSetPixelOffsetMode", "hwnd", $hMemGraph, "int", $iPixOffsetMode)
    $a = DllCall("GDIPlus.dll", "int", "GdipSetPixelOffsetMode", "hwnd", $hScreenGraph, "int", $iPixOffsetMode)
    $a = DllCall("GDIPlus.dll", "int", "GdipSetSmoothingMode", "hwnd", $hMemGraph, "int", $iSmoothMode)
    $a = DllCall("GDIPlus.dll", "int", "GdipSetSmoothingMode", "hwnd", $hScreenGraph, "int", $iSmoothMode)
    _GDIPlus_GraphicsDrawImageRectRect($hMemGraph, $hImg, 0, 0, 580, 240, 30, 420, 580/$nRatio, 240/$nRatio)
    _GDIPlus_GraphicsDrawImageRectRect($hScreenGraph, $hImg2, 0, 0, 580/$nRatio, 240/$nRatio, 30, 420, 580, 240)
msgbox(1,"WAITING","WAITING")
    _WinAPI_DeleteObject($hBMP)
    _GDIPlus_ImageDispose($hImg)
    _GDIPlus_ImageDispose($hImg2)
    _GDIPlus_GraphicsDispose($hMemGraph)
    _GDIPlus_GraphicsDispose($hScreenGraph)
    _WinAPI_ReleaseDC(0, $hScreenDC)
EndFunc

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...