Sign in to follow this  
Followers 0
Anas

GDI+ CPU Usage

6 posts in this topic

Hello

If I run a GDIplus code in a loop then run a Game, WMP or some webpages (like Youtube) the CPU usage increases from 0 to 30-45% till that program is closed, is this normal? Can it be avoided without having to increase sleep time?

Example:

#include <GUIConstants.au3>
#include <GDIplus.au3>

Global Const $width=100
Global Const $height=10
GLobal $title="GDI+"

; Build your GUI here
Opt("GUIOnEventMode",1)
$hwnd = GUICreate($title,$width,$height)
GUISetOnEvent($GUI_EVENT_CLOSE, "close")
GUISetState()

; Load your GDI+ resources here:
_GDIPlus_Startup()
$graphics=_GDIPlus_GraphicsCreateFromHWND($hwnd)
$bitmap=_GDIPlus_BitmapCreateFromGraphics($width,$height,$graphics)
$backbuffer=_GDIPlus_ImageGetGraphicsContext($bitmap)

$hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
$hFormat = _GDIPlus_StringFormatCreate()
_GDIPlus_StringFormatSetAlign($hFormat, 1)

Do
    _GDIPlus_GraphicsClear($backbuffer)

    $hFamily = _GDIPlus_FontFamilyCreate("7px2bus")
    $hFont = _GDIPlus_FontCreate($hFamily, 5.5, 0)

    $tLayout = _GDIPlus_RectFCreate(8, 3, 0, 0)
    _GDIPlus_GraphicsDrawStringEx($backbuffer, "0", $hFont, $tLayout, $hFormat, $hBrush)

    _GDIPlus_GraphicsDrawImageRect($graphics,$bitmap,0,0,$width,$height)
    Sleep(10)
Until False

Func close()
    _GDIPlus_GraphicsDispose($backbuffer)
    _GDIPlus_BitmapDispose($bitmap)
    _GDIPlus_GraphicsDispose($graphics)
    _GDIPlus_Shutdown()
    Exit
EndFunc

Share this post


Link to post
Share on other sites



On Windows XP (or older) or Vista (or newer) with Aero disabled, GDI+ is all done on the main processor and not on the graphics card. This is probably what you are experiencing.

Share this post


Link to post
Share on other sites

I meant the process CPU usage, not the overall CPU usage.

and the same script will run with almost no CPU usage without these programs/content.

Share this post


Link to post
Share on other sites

I'm afraid I've never seen a situation like that before.

I just tested your code and ran several things like a media player and some YouTube videos. The processor time on the AutoIt process stayed below 3% for me.

Share this post


Link to post
Share on other sites

Actually I just tested it, and unlike the one I use, it seems that this one is only affected by Games ;)

can you please test it with a directx game?

Share this post


Link to post
Share on other sites

I haven't got any DirectX games installed on my laptop, sorry.

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