Jump to content

show images without using much cpu


Go to solution Solved by UEZ,

Recommended Posts

@Belinimaybe you have adjust the path to the images. Just debug to console in the load loop in line 13 to see if handle is created.

ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $hImage = ' & $hImage & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

Tested on Win11.

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

Now it worked but it doesn't occupy all desktop as i need it, the gui is being created in the dimensions of the image and i need the gui and the image to be the same size as the desktop.

Global Const $hGUI = GUICreate("Test", @DesktopWidth, @DesktopHeight, $WS_POPUP)

The image just occupies the whole desktop using _GDIPlus_ImageResize() but then the cpu usage gets very high.

Edited by Belini
Link to comment
Share on other sites

  • Solution

I added in the main loop a line to resize the image _WinAPI_StretchBlt:

;_WinAPI_BitBlt($hDC, 0, 0, $iW, $iH, $hGfxDC, 0, 0, $SRCCOPY)
    _WinAPI_StretchBlt($hDC, 0, 0, @DesktopWidth, @DesktopHeight, $hGfxDC, 0, 0, $iW, $iH, $SRCCOPY) ;resize

This should stretch the image to your desktop.

 

Btw, what is your CPU load now with my example?

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

Amazing @UEZ 0% to 1% cpu usage now, thanks for helping to solve this problem.

EDITED: How would it look in your example to search for images on disk instead of saving them in memory?

Edited by Belini
Link to comment
Share on other sites

35 minutes ago, pixelsearch said:

@UEZ Glad to have you back on the Forum :)

I took a "short" break. 😉

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

45 minutes ago, Belini said:

Amazing @UEZ 0% to 1% cpu usage now, thanks for helping to solve this problem.

EDITED: How would it look in your example to search for images on disk instead of saving them in memory?

For sure the CPU / HDD usage will increase. My CPU usage is ~1-5% but memory consumption is ~15 mb now.

;Coded by UEZ build 2023-05-31
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

AutoItSetOption("GUIOnEventMode", 1)

_GDIPlus_Startup()
Global $i, $hImage, $hGDIBitmap, $hObjOld, $bExit = False
Global Const $hGUI = GUICreate("Test", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP)
GUISetState()
Global Const $hDC = _WinAPI_GetDC($hGUI), _
             $hGfxDC = _WinAPI_CreateCompatibleDC($hDC)

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

$i = 1
Do
    $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Test\" & $i & ".jpg")
    $i += 1
    If $i > 169 Then $i = 1
    $hGDIBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    _GDIPlus_ImageDispose($hImage)
    $hObjOld = _WinAPI_SelectObject($hGfxDC, $hGDIBitmap)
    _WinAPI_StretchBlt($hDC, 0, 0, @DesktopWidth, @DesktopHeight, $hGfxDC, 0, 0, 1280, 720, $SRCCOPY) ;resize
    _WinAPI_SelectObject($hGfxDC, $hObjOld)
    _WinAPI_DeleteObject($hGDIBitmap)
    If $bExit Then ExitLoop
Until Not Sleep(10)

_WinAPI_ReleaseDC($hGUI, $hDC)
_WinAPI_DeleteDC($hGfxDC)
_GDIPlus_Shutdown()

Func _Exit()
    $bExit = True
EndFunc

 

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

@UEZ perfect now around ~10 - 15% of the cpu but it has greatly reduced memory usage, thank you very much for your help.

Edited by Belini
Link to comment
Share on other sites

13 minutes ago, Belini said:

@UEZ perfect now around ~10 - 15% of the cpu but it has greatly reduced memory usage, thank you very much for your help.

You are welcome. You can play with the Sleep value to reduce CPU usage, for example set it to Sleep(30). The CPU usage should be decreased but also the animation speed.

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

Player output using .jpg images with GDI:

 

15 images per second with a 50 millisecond interval between images.

Edited by Belini
Link to comment
Share on other sites

I'm finding the images not very clear as if they were in 16 bits, there is a way to improve the images by setting them to be shown in 24 bits, the images were extracted in 1280x720 and in 24 bits but it seems to lose quality when displayed.

Link to comment
Share on other sites

Does anyone have any tips for improving the image that is displayed on the screen?

Link to comment
Share on other sites

I stand my previous position and I'm saying it again: you are doing it wrong and in wrong programming language. Switching image files and expecting to be like a video file playing it's just wrong (not to say it's kinda stupid) so if you really want to go on that way probably you won't find much support since people don't really like to spend time improving such an obvious wrong implementation. It's just my position, so don't be offended. I hope you will eventually find someone to help finish your project.

Link to comment
Share on other sites

@Andreik I am not offended but I reinforce that I really need the image player because sometimes I need two players at the same time, one to play background video and the other to play cdg which is very heavy and most of the time does not support opening two at the same time being able to control both separately and if I can't improve the image quality using GDI then I'll have to look for another way to display images as if it were a video.

EDIT: I wanted to try with sdl2.dll, does anyone have an example of how to use sdl2.dll to display images?

Edited by Belini
Link to comment
Share on other sites

@Belini: you can use 

_WinAPI_SetStretchBltMode($hDC, $STRETCH_HALFTONE)
_WinAPI_SetBrushOrg($hDC, 0, 0)

to produces higher quality images but this mode is slower and requires more processing of the source image.

I personally don't see any improvement of the images, only higher CPU usage and slower execution.

Anyhow, here the code:

;Coded by UEZ build 2023-06-16
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

AutoItSetOption("GUIOnEventMode", 1)

_GDIPlus_Startup()
Global $i, $hImage, $hGDIBitmap, $hObjOld, $bExit = False
Global Const $hGUI = GUICreate("Test", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP)
GUISetState()
Global Const $hDC = _WinAPI_GetDC($hGUI), _
             $hGfxDC = _WinAPI_CreateCompatibleDC($hDC)

_WinAPI_SetStretchBltMode($hDC, $STRETCH_HALFTONE)
_WinAPI_SetBrushOrg($hDC, 0, 0)

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

$i = 1
Do
    $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Test\" & $i & ".jpg")
    $i += 1
    If $i > 169 Then $i = 1
    $hGDIBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    _GDIPlus_ImageDispose($hImage)
    $hObjOld = _WinAPI_SelectObject($hGfxDC, $hGDIBitmap)
    _WinAPI_StretchBlt($hDC, 0, 0, @DesktopWidth, @DesktopHeight, $hGfxDC, 0, 0, 1280, 720, $SRCCOPY) ;resize
    _WinAPI_SelectObject($hGfxDC, $hObjOld)
    _WinAPI_DeleteObject($hGDIBitmap)
    If $bExit Then ExitLoop
Until Not Sleep(10)

_WinAPI_ReleaseDC($hGUI, $hDC)
_WinAPI_DeleteDC($hGfxDC)
_GDIPlus_Shutdown()

Func _Exit()
    $bExit = True
EndFunc

 

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

@UEZ is really much slower using these options and it won't compensate for the little gain in image quality, thanks for helping once again.

Link to comment
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
 Share

  • Recently Browsing   0 members

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