Jump to content
Sign in to follow this  
DOTCOMmunications

Images display with black squares on them

Recommended Posts

DOTCOMmunications

Hi all

I am wondering if someone knows what could be causing the images in my GUI to display little black squares all over them. They seem to change depending on how much code is in the file/program.

I have attached two examples, the first is from a set of buttons called using GUICtrlCreatePic and they are in BMP format

post-60602-0-44654600-1354552051_thumb.j

Shows a screenshot of the GUI image on the left and the original images on the right

The second is also called using GUICtrlCreatePic but they are in JPG format

post-60602-0-21163300-1354552059_thumb.j

Shows a screenshot of the GUI image on the top and the original image on the bottom

Both of them display the same problem although in earlier versions of the code it seemed to just exist on the BMP buttons, although i havent been watching it closely until i noticed them in both places today. They show up whether the script is compiled or not.

Thanks in advance

Adam

Share this post


Link to post
Share on other sites
wraithdu

Check the remarks in GUICtrlCreatePic regarding the WS_EX_LAYERED GUI style and transparent images. If that doesn't apply, then I'm out of ideas.

Share this post


Link to post
Share on other sites
UEZ

I don't know whether this is a feature or a bug in GUICtrlCreatePic() function. A possible workaround is to load the images with GDI+ and send it to the picture control.

There are a lot of examples how to load an image in GDI+ and send it to a control.

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
DOTCOMmunications

Check the remarks in GUICtrlCreatePic regarding the WS_EX_LAYERED GUI style and transparent images. If that doesn't apply, then I'm out of ideas.

Thanks for the reply, i have checked some of the GUIs in question and the only style we use on them is WS_POPUP and barely use extended styles at all throughout the program

I don't know whether this is a feature or a bug in GUICtrlCreatePic() function. A possible workaround is to load the images with GDI+ and send it to the picture control.

There are a lot of examples how to load an image in GDI+ and send it to a control.

Br,

UEZ

I did look at GDI+ briefly quite a while back but i couldnt really get it to work, do you have a simple small example i could try?

Share this post


Link to post
Share on other sites
UEZ

Can you provide a bmp with the problem?

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
UEZ

Try this:

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

_GDIPlus_Startup()
$hGUI = GUICreate("Test", 200, 140)
GUISetBkColor(0x0, $hGUI)
$idPic_Default1 = GUICtrlCreatePic(@ScriptDir & "SwitchOn.bmp", 20, 20, 0, 0)
$idPic_Default2 = GUICtrlCreatePic(@ScriptDir & "SwitchOff.bmp", 20, 90, 0, 0)
$idPic_GDIP1 = GUICtrlCreatePic("", 120, 20, 0, 0)
_GDIPlus_SendImage2Control(@ScriptDir & "SwitchOn.bmp", $idPic_GDIP1)
$idPic_GDIP2 = GUICtrlCreatePic("", 120, 90, 0, 0)
_GDIPlus_SendImage2Control(@ScriptDir & "SwitchOff.bmp", $idPic_GDIP2)
GUISetState()

Do
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            GUIDelete()
            _GDIPlus_Shutdown()
            Exit
    EndSwitch
Until False

Func _GDIPlus_SendImage2Control($sImageFile, $idControl) ;coded by UEZ 2012
    Local $hBitmap = _GDIPlus_BitmapCreateFromFile($sImageFile)
    If @error Then Return SetError(1, 0, 0)
    Local Const $IMAGE_BITMAP = 0, $STM_SETIMAGE = 0x0172
    Local $hHBmp
    If @OSBuild < 6000 Then
        $hHBmp = _GDIPlus_ConvertTransparentBitmap($hBitmap)
    Else
        $hHBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    EndIf
    _GDIPlus_BitmapDispose($hBitmap)
    Local $hResult = GUICtrlSendMsg($idControl, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBmp)
    If $hResult Then _WinAPI_DeleteObject($hResult)
EndFunc

Func _GDIPlus_ConvertTransparentBitmap($hBitmap) ;coded by UEZ 2012
    Local $iButtonColor = _WinAPI_GetSysColor($COLOR_BTNFACE)
    $iButtonColor = 0x10000 * BitAND($iButtonColor, 0xFF) + BitAND($iButtonColor, 0x00FF00) + BitShift($iButtonColor, 16)
    Local $iWidth = _GDIPlus_ImageGetWidth($hBitmap), $iHeight = _GDIPlus_ImageGetHeight($hBitmap)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0)
    Local $hBitmap_New = $aResult[6]
    Local $hCtx_new = _GDIPlus_ImageGetGraphicsContext($hBitmap_New)
    Local $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000 + $iButtonColor)
    _GDIPlus_GraphicsFillRect($hCtx_new, 0, 0, $iWidth, $iHeight, $hBrush)
    _GDIPlus_GraphicsDrawImageRect($hCtx_new, $hBitmap, 0, 0, $iWidth, $iHeight)
    Local $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_New)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_BitmapDispose($hBitmap_New)
    _GDIPlus_GraphicsDispose($hCtx_new)
    Return $hHBitmap
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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
DOTCOMmunications

Thanks for that example

The GDI+ example doesn't suffer from the same issue, will take a look at re-coding the GUI to use GDI+, do any of the other controls (labels, progress bars) etc get affected by GDI+? Also does GDI+ work natively on Windows XP, Vista and 7?

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  

  • Similar Content

    • odaylton
      By odaylton
      Hello everyone ,
      Text translated from Portuguese by google - please apologize for any errors

      Once again I need a light from the gurus of this wonderful website
      I am fanatic by combobox for its usability but I am not able to uncertain images within lists ...
      I know uncertain icons, and cursors but I am not able to insert gif or jpg images.
      1) How to solve this ...
      2) will the path is to convert gif into bmp and then uncertain ... how to do that?
      #include <GUIConstantsEx.au3> #include <GuiImageList.au3> #include <GuiListView.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> ;dados de mouse #include <WinAPIRes.au3> ;COMBO #include <GuiComboBoxEx.au3> ;Fonts #include <FontConstants.au3> ;obter imagem de arquivo #include <GDIPlus.au3> #include <WinAPIGdi.au3> Example() Func Example() Local $hGUI, $hImage, $hCombo, $hFont Local $idListview, $hImage Local $sWow64 = "" Local $Pasta = "C:\WINDOWS\Cursors\3dgarro.cur" Local $PastaROMs = @MyDocumentsDir & "\Stella\ROMs\" ;com barra no final $hGUI = GUICreate("ImageList", 500, 310) GUISetFont(14, 400, 0, "Arial") ;<<<<<<<<<<this does not work for _GUICtrlComboBoxEx_Create $hCombo = _GUICtrlComboBoxEx_Create($hGUI, "", 2, 2, 494, 200) ;GUICtrlSetFont($hCombo, 14, 400, 0, "Arial");<<<<<<<<<<It does not work ; ;Create a handle to a font object $hFont = _WinAPI_CreateFont(30, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Arial') ;Pass the handle to _WinAPI_SetFont _WinAPI_SetFont($hCombo, $hFont) $idListview = GUICtrlCreateListView("", 2, 50, 494, 250, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT)) _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER)) GUISetState(@SW_SHOW) ; Initialize GDI+ library _GDIPlus_Startup() ; Load images $hImage = _GUIImageList_Create(120, 70, 6, 2) ;32,32,5,5) ; $DadosCombo = "Escolha|" & _GUIImageList_Add($hImage, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, 0x0000FF, 120, 70)) ;Local $aCursors[] = [32650, 32512, 32515, 32649, 32651, 32513, 32648, 32646, 32643, 32645, 32642, 32644, 32516, 32514] For $i = 1 To 10 $sFile = FileOpenDialog("Please select an image", $PastaROMs, "Image (*.jpg;*.png;*.bmp;*.gif;*.tif)", BitOR($FD_PATHMUSTEXIST, $FD_FILEMUSTEXIST)) If @error Then Exit MsgBox(BitOR($MB_TOPMOST, $MB_ICONERROR), "Error", "No image file has been selected", 30) $a = _GDIPlus_BitmapCreateFromFile ($sFile);<<<<< ok If @error Or Not $hImage Then MsgBox(BitOR($MB_TOPMOST, $MB_ICONERROR), "Error", "This file isn't supported by GDIPlus!") Else $b=_GUIImageList_Add($hImage, $a);<<<<<< Return -1 $DadosCombo &= "|" & $i & "_img_princ.gif""|" & $b EndIf Next _GUICtrlListView_SetImageList($idListview, $hImage, 1) _GUICtrlComboBoxEx_SetImageList($hCombo, $hImage) ; Add columns _GUICtrlListView_AddColumn($idListview, "Icons - Mouses", 350) ; Add items $a = StringSplit($DadosCombo, "|") For $i = 1 To $a[0] Step 2 _GUICtrlListView_AddItem($idListview, $a[$i], $a[$i + 1]) _GUICtrlComboBoxEx_AddString($hCombo, $a[$i], $a[$i + 1], $a[$i + 1]) Next ;AutoIt_Debugger_Command:Disable_Debug ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() ;AutoIt_Debugger_Command:Enable_Debug EndFunc ;==>Example tks
    • corz
      By corz
      We've been able to drag images out of web browsers since forever. Can I drag one into my GUI?
      Or rather, can I drag an image from my web browser onto my GUI and have my app *do* something with that image?
      My fingers bleed from searching. Any ideas much appreciated!
      ;o) Cor
    • fatpig
      By fatpig
      can anyone tell me how I stop this from occuring when I place a jpg in my GUI?
      White parts become black. might be transparent, too. Not sure.
      thanks

×