Jump to content

<icons.au3> gdiplus under win2000 problems transparent gif


Mungo
 Share

Recommended Posts

I have compiled my script which uses <icons.au3> by Yashied (requiring gdiplus.dll) to display transparent gifs.

http://www.autoitscript.com/forum/index.php?showtopic=92675

It works perfectly alright under XP (under classic as well XP desktop theme) but gives me a black colour instead of the transparency under WIN2000 (see two screenshots below). I have installed gdiplus on the WIN2000 system to see the gifs at all. I load the gif images as follows:

#Include <Icons.au3>
...
_GDIPlus_Startup()
... 
$c_image_02 = @ScriptDir & "\c_image_02.gif"
....
$pic_02 = GUICtrlCreatePic('  ', 10, 10, 94, 16) 
_SetImage($pic_02, $c_image_02 )

The win2000(left) and XP(right) screens attached.

I am a bit puzzled - any ideas.

Thanks

Mungo

post-57589-12774786196572_thumb.jpg

post-57589-12774786356994_thumb.jpg

Edited by Mungo
Link to comment
Share on other sites

Not all Win 2000 systems have the GDI+ dll installed. You can get it here but check to see if gdiplus.dll exists first. As I recall you don't have to register that dll.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Thanks both of you,

Below is one of the ~ 16 gifs, exactly the one from the screenshot, I use (just named differently).

As to GDI+ . I have two quite different WIN2000 machines (age, graphics, etc one with SiS 5598/6326 24bit and the other Nvidia Riva TNT2 with 32 bit colour depth). On both was no GDI+ present which manifested in those gifs being just totally invisible with only the grey program background to be seen. After some searching I found the hint with the missing gdiplus and I tried and placed the gdiplus.dll in the system32 dir and my program dir (not at the same time) and the effects where the same on both machines. I use the latest dll version downloaded from MS site as well as the version George has pointed out to me.

As I do not have too much insights I thought of trying converting those gifs to png and see whether the effect will prevail ....

Thanks

Cheers

Mungo

post-57589-1277520276213_thumb.gif

Link to comment
Share on other sites

Can you try the following script:

#include <GDIPlus.au3>

Local Const $STM_SETIMAGE = 0x0172
Local $hGUI, $Pic, $hImage, $hBmp, $iW, $iH

ConsoleWrite("_GDIPlus_Startup" & @TAB & _GDIPlus_Startup() & @CRLF)
$hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\c_image_02.gif")
$iW = _GDIPlus_ImageGetWidth($hImage)
$iH = _GDIPlus_ImageGetHeight($hImage)
$hBitmap = _GDIPlus_BitmapCloneArea($hImage, 0, 0, $iW, $iH, $GDIP_PXF24RGB)
$hBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)

_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_ImageDispose($hImage)

$hGUI = GUICreate("Test", $iW+20, $iH+20)
$Pic = GUICtrlCreatePic("", 10, 10, $iW, $iH)

GUICtrlSendMsg($Pic, $STM_SETIMAGE, 0, $hBmp)
_WinAPI_DeleteObject($hBmp)

GUISetState()
Do
Until GUIGetMsg() = -3
GUIDelete()

_GDIPlus_Shutdown()

Do you get _GDIPlus_Startup True in the console?

Link to comment
Share on other sites

I tried your script exactly as you posted it. GDI is loaded, console shows "_GDIPlus_Startup True" on both the XP and the Win2000. However, the gif does not show on the Win2000, just grey, as to the screen shots below.

Initially I ran my program as a compiled exe on the Win2000. Tried to do the same with your test script (not to have to install AutoIt on the Win2000) but my AV (F-Prot) blocked the compilation with w32/dropper.bcgx warning ... hmmm?! (any idea?) ... Well, installed AutoIt on the Win2000 and ran script. I also tried my original script (uncompiled) and same results as originally reported for the compiled version.

Cheers

Mungo

(Win2000 left, xp right)

post-57589-12775450163364_thumb.jpg

post-57589-12775450429029_thumb.jpg

Edited by Mungo
Link to comment
Share on other sites

Strange, can you post the console output:

#include <GDIPlus.au3>

Local Const $STM_SETIMAGE = 0x0172
Local $hGUI, $Pic, $hImage, $hBmp, $iW, $iH

_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\c_image_02.gif")
ConsoleWrite(StringFormat("%-40s @error: %i, @extended: %i, Return: %#.8x\n", "_GDIPlus_ImageLoadFromFile", @error, @extended, $hImage))
$iW = _GDIPlus_ImageGetWidth($hImage)
ConsoleWrite(StringFormat("%-40s @error: %i, @extended: %i, Return: %i\n", "_GDIPlus_ImageGetWidth", @error, @extended, $iW))
$iH = _GDIPlus_ImageGetHeight($hImage)
ConsoleWrite(StringFormat("%-40s @error: %i, @extended: %i, Return: %i\n", "_GDIPlus_ImageGetHeight", @error, @extended, $iH))
$hBitmap = _GDIPlus_BitmapCloneArea($hImage, 0, 0, $iW, $iH, $GDIP_PXF24RGB)
ConsoleWrite(StringFormat("%-40s @error: %i, @extended: %i, Return: %#.8x\n", "_GDIPlus_BitmapCloneArea", @error, @extended, $hBitmap))
$hBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
ConsoleWrite(StringFormat("%-40s @error: %i, @extended: %i, Return: %#.8x\n", "_GDIPlus_BitmapCreateHBITMAPFromBitmap", @error, @extended, $hBmp))

_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_ImageDispose($hImage)

$hGUI = GUICreate("Test", $iW+20, $iH+20)
$Pic = GUICtrlCreatePic("", 10, 10, $iW, $iH)

GUICtrlSendMsg($Pic, $STM_SETIMAGE, 0, $hBmp)
_WinAPI_DeleteObject($hBmp)

GUISetState()
Do
Until GUIGetMsg() = -3
GUIDelete()

_GDIPlus_Shutdown()
Link to comment
Share on other sites

Here the console output,

Thanks

+>22:37:49 Starting AutoIt3Wrapper v.2.0.1.24    Environment(Language:0409  Keyboard:00000407  OS:WIN_2000/Service Pack 4  CPU:X86 OS:X86)
>Running AU3Check (1.54.19.0)  from:C:\programs\auto_it
+>22:37:51 AU3Check ended.rc:0
>Running:(3.3.6.1):C:\programs\auto_it\autoit3.exe "D:\data_aus_hilli\thomas\programming\auto_it\tms_backup\bits_and_pieces\gdi\test_gdi_03.au3"    
_GDIPlus_ImageLoadFromFile               @error: 0, @extended: 0, Return: 0x02633918
_GDIPlus_ImageGetWidth                   @error: 0, @extended: 0, Return: 94
_GDIPlus_ImageGetHeight                  @error: 0, @extended: 0, Return: 16
_GDIPlus_BitmapCloneArea                 @error: 0, @extended: 0, Return: 0x02634ec0
_GDIPlus_BitmapCreateHBITMAPFromBitmap   @error: 0, @extended: 0, Return: 0x22050994
+>22:38:13 AutoIT3.exe ended.rc:0
>Exit code: 0    Time: 30.871
Link to comment
Share on other sites

lol, sorry for exhausting you with tests. I suspect it's the STM_SETIMAGE, but I can't be so sure.

What you see when you run this script:

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Local $hGUI, $hGraphics, $hImage, $iW, $iH

_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\c_image_02.gif")
$iW = _GDIPlus_ImageGetWidth($hImage)
$iH = _GDIPlus_ImageGetHeight($hImage)

$hGUI = GUICreate("Test", $iW+20, $iH+20)
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)

GUIRegisterMsg($WM_PAINT, "_WM_PAINT")
GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

_GDIPlus_GraphicsDispose($hGraphics)
GUIDelete()

_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()

Func _WM_PAINT($hWnd, $iMsg, $iwParam, $ilParam)
    Sleep(20)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hImage, 10, 10)

    Return $GUI_RUNDEFMSG
EndFunc
Link to comment
Share on other sites

lol, sorry for exhausting you with tests. I suspect it's the STM_SETIMAGE, but I can't be so sure.

What you see when you run this script:

[....]

Don't mind doing the testing and, yes, it looks like you found it ... a bit of a miracle to me though! :mellow: It shows perfectly alright now (see below).

Any suggestions - in layman terms ?

Thanks!!

post-57589-12775616309676_thumb.jpg

Link to comment
Share on other sites

Try to update your system to SP3. Also, try other updates that window may find. It has nothing to do with your graphics driver/card rather than the system.

Thanks again for your help!

Sorry for coming back on this issue. I originally assumed that there might be something wrong with my script or the <icons.au3> UDF library ... ? Well, the system is kept up to date, by the way SP 4 (see console output), and all updates are normally run as suggested by the automatic MS updates - will keep looking though. So I am a bit stuck and puzzled here especially as I have the same effect on two totally different Win2000 machines. Both with latest updates and service packs etc.

Have you tried to use <icons.au3> ?

Cheers

Mungo

Edited by Mungo
Link to comment
Share on other sites

Yes, Icons.au3 work flawlessly over here on XP pro.

Try the previous non-working script from post #5. Put this after the GUICtrlSendMsg:

ConsoleWrite(_WinAPI_GetLastErrorMessage())

It may or may not help. Try this one as well:

#include <WinAPI.au3>

Local Const $RASTERCAPS = 38

Local const $RC_BITBLT = 1
Local Const $RC_BANDING = 2
Local const $RC_SCALING = 4
Local const $RC_BITMAP64 = 8
Local const $RC_GDI20_OUTPUT = 16
Local const $RC_DI_BITMAP = 128
Local const $RC_PALETTE = 256
Local const $RC_DIBTODEV = 512
Local const $RC_FLOODFILL = 4096
Local const $RC_STRETCHBLT = 2048
Local const $RC_STRETCHDIB = 8192

Local $hGUI = GUICreate("Test")
Local $Pic = GUICtrlCreatePic("", 0, 0, 100, 100)
Local $hPic = GUICtrlGetHandle($Pic)

$hDC = _WinAPI_GetDC($hPic)
If $hDC Then
    $iDeviceCaps = _WinAPI_GetDeviceCaps($hDC, $RASTERCAPS)

    If BitAND($iDeviceCaps, $RC_BITBLT) Then ConsoleWrite("Capable of transferring bitmaps" & @CRLF)
    If BitAND($iDeviceCaps, $RC_BANDING) Then ConsoleWrite("Requires banding support" & @CRLF)
    If BitAND($iDeviceCaps, $RC_SCALING) Then ConsoleWrite("Capable of scaling" & @CRLF)
    If BitAND($iDeviceCaps, $RC_BITMAP64) Then ConsoleWrite("Capable of supporting bitmaps larger than 64 KB" & @CRLF)
    If BitAND($iDeviceCaps, $RC_GDI20_OUTPUT) Then ConsoleWrite("Supports Windows 2.0 features" & @CRLF)
    If BitAND($iDeviceCaps, $RC_DI_BITMAP) Then ConsoleWrite("Capable of supporting the SetDIBits and GetDIBits functions" & @CRLF)
    If BitAND($iDeviceCaps, $RC_PALETTE) Then ConsoleWrite("Specifies a palette-based device" & @CRLF)
    If BitAND($iDeviceCaps, $RC_DIBTODEV) Then ConsoleWrite("Capable of supporting the SetDIBitsToDevice function" & @CRLF)
    If BitAND($iDeviceCaps, $RC_FLOODFILL) Then ConsoleWrite("Capable of performing flood fills" & @CRLF)
    If BitAND($iDeviceCaps, $RC_STRETCHBLT) Then ConsoleWrite("Capable of performing the StretchBlt function" & @CRLF)
    If BitAND($iDeviceCaps, $RC_STRETCHDIB) Then ConsoleWrite("Capable of performing the StretchDIBits function" & @CRLF)

    _WinAPI_ReleaseDC($hPic, $hDC)
EndIf

GUIDelete()

Just wandering in darkness...

Link to comment
Share on other sites

Yes, Icons.au3 work flawlessly over here on XP pro.

Try the previous non-working script from post #5. Put this after the GUICtrlSendMsg:

ConsoleWrite(_WinAPI_GetLastErrorMessage())

[...]

Get the following message on XP as well as Win2000

_GDIPlus_Startup    True
Not enough storage is available to process this command.

I ran your other test and results are identically on XP and Win2000 (output below)

+>15:08:03 Starting AutoIt3Wrapper v.2.0.1.24    Environment(Language:0409  Keyboard:00000407  OS:WIN_2000/Service Pack 4  CPU:X86 OS:X86)
>Running AU3Check (1.54.19.0)  from:C:\programs\auto_it
+>15:08:03 AU3Check ended.rc:0
>Running:(3.3.6.1):C:\programs\auto_it\autoit3.exe "D:\gdi\test_gdi_05.au3"    
Capable of transferring bitmaps
Capable of supporting bitmaps larger than 64 KB
Supports Windows 2.0 features
Capable of supporting the SetDIBits and GetDIBits functions
Capable of supporting the SetDIBitsToDevice function
Capable of performing flood fills
Capable of performing the StretchBlt function
Capable of performing the StretchDIBits function
+>15:08:04 AutoIT3.exe ended.rc:0
>Exit code: 0    Time: 2.658

I also tried it with a png version but had the same effect.

Finding someone with a Win2000 machine is probably getting hard, however maybe someone is out there and could give the following script a go?

#include <GUIConstantsEx.au3>
#Include <Icons.au3>

f_gdi_test()

Func f_gdi_test()

    $image_01 = @ScriptDir & "\image_01.gif"
    $image_02 = @ScriptDir & "\image_02.png"
    
    $gen_win = GUICreate ( "GDI ... ", 250, 200)
    
    GUICtrlCreateLabel("GDI Test on Win2000 - does transparency show?", 10, 10)
    GUICtrlCreateLabel("GDI Test - gif", 10, 50)
    
    $test_image_01 = GUICtrlCreatePic('', 10, 70, 94, 16)
    _SetImage($test_image_01, $image_01)
    GUICtrlCreateLabel("GDI Test - png", 10, 100)
    $test_image_02 = GUICtrlCreatePic('', 10, 120, 94, 16)
    _SetImage($test_image_02, $image_02)

    $okbutton = GUICtrlCreateButton("OK", 85, 160, 80, -1 )

    GUISetState(@SW_SHOW)

    While 1
    $msg_pop = GUIGetMsg(1)
        Select
            Case $msg_pop[0] = $GUI_EVENT_CLOSE
            ExitLoop
            Case $msg_pop[0] = $okbutton
            ExitLoop
        EndSelect
     WEnd
    GUIDelete()
EndFunc

The two images below.

Thanks!!

post-57589-12776269882971_thumb.gif

post-57589-12776270155191_thumb.png

Edited by Mungo
Link to comment
Share on other sites

This code worked for me under Windows2000 Server in a vm:

;Coded by UEZ
#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
Opt('MustDeclareVars', 1)
Opt("GUIOnEventMode", 1)
Global $hWnd, $hGraphic, $file, $hImage
Global $iX, $iY

$file = FileOpenDialog("Select image to load", @ScriptDir, "Images (*.jpg;*.png;*.bmp;*.gif)")

_GDIPlus_Startup()

$hImage = _GDIPlus_ImageLoadFromFile($file)
If Not $hImage Then Exit _GDIPlus_Shutdown()
$iX = _GDIPlus_ImageGetWidth($hImage)
$iY = _GDIPlus_ImageGetHeight($hImage)

$hWnd = GUICreate("Display Image: " & $file, $iX, $iY)
GUISetBkColor(0xF0F0F0)
GUISetState()

$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, $iX, $iY)

GUIRegisterMsg(0x000F, "WM_PAINT") ;$WM_PAINT = 0x000F
GUIRegisterMsg(0x0014 , "WM_ERASEBKGND") ;WM_ERASEBKGND = 0x0014

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

Do
Until Not Sleep(10000000)

Func _Exit()
    GUIRegisterMsg(0x000F, "")
    GUIRegisterMsg(0x0014, "")
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    Exit
EndFunc

Func WM_PAINT()
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, $iX, $iY)
    Return "GUI_RUNDEFMSG"
EndFunc ;==>WM_PAINT

Func WM_ERASEBKGND()
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, $iX, $iY)
    Return "GUI_RUNDEFMSG"
EndFunc

BR,

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,

Thanks for your response and code! Sorry for my late response but I had been away and then fairly busy.

Concerning your posting. I am not quite sure whether I got it right or not (from your posting) but did you actually got around testing my code in your Win2000 VM? I mean the code I posted in message #14 and which uses <Icons.au3> ?

I ran your script on my Win2000 and it works perfectly well and the images are transparent - so I assume gdiplus works alright ...

However, I still haven't figured out why then your scrip runs fine but the one I posted using the <Icons.au3> library doesn't (at least on my Win2000 machine).

Maybe this will stay a mistery ... ?

Thanks

Cheers

Mungo

Edited by Mungo
Link to comment
Share on other sites

UEZ,

Thanks for your response and code! Sorry for my late response but I had been away and then fairly busy.

Concerning your posting. I am not quite sure whether I got it right or not (from your posting) but did you actually got around testing my code in your Win2000 VM? I mean the code I posted in message #14 and which uses <Icons.au3> ?

I ran your script on my Win2000 and it works perfectly well and the images are transparent - so I assume gdiplus works alright ...

However, I still haven't figured out why then your scrip runs fine but the one I posted using the <Icons.au3> library doesn't (at least on my Win2000 machine).

Maybe this will stay a mistery ... ?

Thanks

Cheers

Mungo

I ran your code in the VM (WIndows2000 Server) and both images look like the first image from your post#14 (black background).

If I look into Yashied's code (Func _SetImage()) I can see that he uses also GDI+ functions to read the image from file but he uses WinAPI functions to convert the image and it might be that WinAPI cannot handle transparent images properly...

BR,

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

I ran your code in the VM (WIndows2000 Server) and both images look like the first image from your post#14 (black background).

If I look into Yashied's code (Func _SetImage()) I can see that he uses also GDI+ functions to read the image from file but he uses WinAPI functions to convert the image and it might be that WinAPI cannot handle transparent images properly...

BR,

UEZ

Thanks a lot UEZ !

At least I know it's not completely wrong what I am coding and that you had the same effect using Yashid's <icons.au3> library.

I though of re-coding as to your example but haven't got enough time at the moment. Considering the very few Win2000 installations who will potentially use the program at the moment I opted for a (admittedly not so nice but quick) work around by just creating an additional set of images and using the Win2000 standard colour scheme (grey) as background for those images instead of transparency. Starting the program I just check for the OS and flip them if a Win2000 is being used ... :blink:

Maybe Yashied might be interested to know.

Many thanks again.

Cheers

Mungo

Edited by Mungo
Link to comment
Share on other sites

Did you try the same image in different formats or bit depths? There are quite a lot of freewares around that can do that. Try the converted image again using the Icons.au3 library. I suspect it's not the library it self, rather the image or system encoders. I think so because what Icons.au3 does (in short) is this:

#include <GDIPlus.au3>

Local Const $STM_SETIMAGE = 0x0172
Local $hGUI, $Pic1, $Pic2, $hImage, $hThumbnail, $hBmpPic1, $hBmpPic2, $iW, $iH

_GDIPlus_Startup()

$hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\c_image_02.gif")
$iW = _GDIPlus_ImageGetWidth($hImage)
$iH = _GDIPlus_ImageGetHeight($hImage)

$hGUI = GUICreate("Test", $iW+20, $iH+60)
; 1:1 as image dimensions
$Pic1 = GUICtrlCreatePic("", 10, 10, $iW, $iH)
; Bigger or smaller control dimensions
$Pic2 = GUICtrlCreatePic("", 10, $iH+20, 40, 40)

; If the control is bigger or smaller than the image dimensions,
; it should be scaled to fit the control dimensions.
$hThumbnail = _GDIPlus_ImageGetThumbnail($hImage, 40, 40)

; Convert GDI+ bitmap objects to GDI bitmap objects
$hBmpPic1 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$hBmpPic2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hThumbnail)

_GDIPlus_ImageDispose($hThumbnail)
_GDIPlus_ImageDispose($hImage)

GUICtrlSendMsg($Pic1, $STM_SETIMAGE, 0, $hBmpPic1) ; 0 = IMAGE_BITMAP
GUICtrlSendMsg($Pic2, $STM_SETIMAGE, 0, $hBmpPic2)
; Clean up
_WinAPI_DeleteObject($hBmpPic2)
_WinAPI_DeleteObject($hBmpPic1)

GUISetState()
Do
Until GUIGetMsg() = -3

GUIDelete()

_GDIPlus_Shutdown()

Func _GDIPlus_ImageGetThumbnail($hImage, $iWidth = 0, $iHeight = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipGetImageThumbnail", "ptr", $hImage, "uint", $iWidth, "uint", $iHeight, "ptr*", 0, "ptr", 0, "ptr", 0)

    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[4]
EndFunc
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...