News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Icons and GDIPlus

Started by guga, October 15, 2020, 04:01:17 AM

Previous topic - Next topic

guga

Ok, succeeded to handle the multiple formats as showed below



But the transparent area of the icon is black when it is displayed inside the static control. How to make it transparent as well ? Also...marinus, does the new icon (with png inside) shows inside the static control on the same way as bitmap in WM_PAINT  ? I mean, to display the image on the static control i did this:

    ...Else_If D@Message = &WM_PAINT
        call 'user32.GetDlgItem' D@Adressee, IDC_STATIC_DISPLAYICONS ; Get thehandle of the static control only. We arte using this handle to update the window (no need to update completelly ?)
        call On_WmPaintBmpRsrc eax, D$Rsrc_hIcon



Proc On_WmPaintBmpRsrc:
    Arguments @Adressee, @hBitmap
    Local @hDC
    Structure @PAINTSTRUCT 64, @PAINTSTRUCT.hdcDis 0
    Uses ecx, edx

    call 'User32.BeginPaint' D@Adressee, D@PAINTSTRUCT
    mov D@hDC eax

    call BmpDrawToDC D@Adressee, eax, D@hBitmap
    call 'USER32.EndPaint' D@Adressee, D@PAINTSTRUCT

EndP


proper way to paint a image onto a DC is with SaveDC/restoreDc

Proc BmpDrawToDC:
    Arguments @Adressee, @hDC, @hBitmap
    Local @ctx, @hMemDC
    Structure @RECT 16, @RECT.leftDis 0, @RECT.topDis 4, @RECT.rightDis 8, @RECT.bottomDis 12
    Uses ecx, edx

    mov D@RECT.leftDis 0
    mov D@RECT.topDis 0
    mov D@RECT.rightDis 0
    mov D@RECT.bottomDis 0

    call 'GDI32.SaveDC' D@hDC | mov D@ctx eax
    call 'GDI32.CreateCompatibleDC' D@hDC | mov D@hMemDC eax
    call 'GDI32.SelectObject' D@hMemDC, D@hBitmap

    call 'User32.GetClientRect' D@Adressee, D@RECT

    call 'GDI32.BitBlt' D@hDC, 0, 0, D@RECT.rightDis, D@RECT.bottomDis, D@hMemDC, 0, 0, &SRCCOPY

    call 'GDI32.RestoreDC' D@hDC, D@ctx
    call 'GDI32.DeleteDC' D@hMemDC

EndP
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

Siekmanski

Hi guga,

Black background....
Did you tried any of the available raster operation codes of the BitBlt function?
You used SRCCOPY ( Copies the source rectangle directly to the destination rectangle. )

Are you sure, that the Alpha values of the Icon background are set to transparent?

Transparent = 0
Translucent = 1 - 254
Opaque = 255
Creative coders use backward thinking techniques as a strategy.

guga

Hi Marinus, yes the icons are transparent

About bitblt i didn´t tried other combinations, because i don´t know what is the transparent color to choose to the AND mask, for example. (The image is drawn on a Static Control on a dialog)

Here it do have an example, but it is presumed to insert the transparent color before the routine starts. Buut how to choose it ? Do i need to take it from the pallete or xor table mask on the icon ?
http://winprog.org/tutorial/transparency.html
https://forums.codeguru.com/showthread.php?108250-Transparent-bitblt
https://www.informit.com/articles/article.aspx?p=20997&seqNum=6

This is the 1st problem, the 2nd one is i´m not being able to update the images when the combobox is changed. If i select the 2nd item in the combobox, for example, the previous image is imposed over the other one instead deleted to later show the new image.

The 3rd problem is that i don´t know how to show new icons, i mean icons that contains png embeded (as the example you posted on save it them).  How do i display a png icn image on a static control ?
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

jj2007

Works fine with Gdi+...

GuiParas equ "Icons", w150, h100, icon Flower, b none
include \masm32\MasmBasic\Res\MbGui.asm
Event Paint
  GuiImage "clouds.jpg", fit ; background image
  GuiImage "269.ico", 5.0, 10.0 ; size the window to see the effects
  GuiImage "Guga.ico", 15.0, 10.0
  GuiImage "Guga.ico", 32.0, 10.0, 50, 50 ; stretched
  GuiImage "Guga.ico", 60.0, 10.0, 40.0, 80.0 ; variably stretched
GuiEnd

Siekmanski

After loading the Icon with Gdi+, you could read the top-left pixel and change the alpha value to 0 of all the same color background pixels to make the background transparent and save it as a PNG icon.
Or save the Icon as an bitmap image and change the background to transparent with a paint program and convert it back to a PNG icon.
Or do it the hard way, getting the background info using the icons XOR/AND masks. ( I personally never worked with these masks..... )

AFAIK, PNG icons are treated the same way as normal icons by the system.
Creative coders use backward thinking techniques as a strategy.