Page 1 of 1

Difference between icons and PNGs on gadgets

Posted: Wed Jun 28, 2023 11:08 pm
by jacdelad
Hi #PB_All,
I encountered a difference between using icons or PNGs on gadgets.

Example ButtonImage (please ignore that the screenshots are slightly different, don't know why the sizes differ):

Image
Icon/PNG enabled

Image
Icon disabled

Image
PNG disabled

The pictures are basically the same (32 bit with alpha). Also multiple reconversion between icon and png doesn't alter the picture itself.
Is the difference normal?

Re: Difference between icons and PNGs on gadgets

Posted: Thu Jun 29, 2023 8:19 am
by Michael Vogel
Maybe you could make the two files available for investigation, but...
...the icon file format does include an additional bit mask information which can be found at the end of the file.

Re: Difference between icons and PNGs on gadgets

Posted: Thu Jun 29, 2023 8:31 am
by Fred
Yes, it's normal as we use the icon directly and Windows has its own greying routine for icons. When using images we use our color to grey routine which looks different.

Re: Difference between icons and PNGs on gadgets

Posted: Thu Jun 29, 2023 12:02 pm
by jacdelad
Thanks you both, I suspected that.

Re: Difference between icons and PNGs on gadgets

Posted: Thu Jun 29, 2023 5:48 pm
by Michael Vogel
I wrote a function which may be helpful for you to convert the icon to "purebasic image format"

Code: Select all

Procedure CopyImageWithDepth(Source.i,Destination.i,Depth=32)

		If ImageDepth(Source,#PB_Image_OriginalDepth)<>Depth Or ImageFormat(Source)=#PB_ImagePlugin_ICON Or ImageFrameCount(Source)<>1			CreateImage(Destination,ImageWidth(Source)+Border<<1,ImageHeight(Source)+Border<<1,Depth,#PB_Image_Transparent);
			StartDrawing(ImageOutput(Destination))
			DrawingMode(#PB_2DDrawing_AllChannels);	Alpha-Channel=255 bei 24-Bit-Bildern (im Default-Modus=0)
			DrawImage(ImageID(Source),Border,Border)
			StopDrawing()
		Else
			CopyImage(Source,Destination)
		EndIf

EndProcedure

Something else I have done for creating dynamic icons (useful for systray animation, etc.), maybe helpful somewhen...

Code: Select all

; File-Header		6 Bytes
Data.w 0;			0 (File Identifier)
Data.w 1;			1=Ico, 2=Cur
Data.w 1;			[n]=Number of Images
; List of Icons		16 Bytes * [n]
Data.a 20;			Width (0=256)
Data.a 20;			Height (0=256)
Data.a 0;			[c]=Color Count (0=256 Colors)
Data.a 0;			0 (Reserved)
Data.w 1;			Ico: Color Planes (0 or 1), Cur: X-Hotspot
Data.w 32;			Ico: Bits per Pixel, Cur: Y-Hotspot
Data.l 1720;		Bitmap Data Size (in bytes, z.B. InfoHeader+20*20*4+XorBitmap)
Data.l 22;			File Offset (InfoHeader)
; Icon Data I		InfoHeader: 40 Bytes
Data.l 40;			Size of InfoHeader
Data.l 20;			Icon Width
Data.l 40;			Icon Height (=XorBitmap + And-Bitmap)
Data.w 1;			Number of Planes (1)
Data.w 32;			Ico: Bits per Pixel
Data.l 0;			Compression-Type (0=uncompressed)
Data.l 0;			Size of Image in Bytes (0=uncompressed)
Data.l 0;			X-PixelsPerM (0=unused)
Data.l 0;			Y-PixelsPerM (0=unused)
Data.l 0;			Colors used (0=unused)
Data.l 0;			Colors important (0=unused)
; Icon Data II		Color Map for Xor-Bitmap: 4 Bytes * [c]
Data.a 255;			red
Data.a 255;			green
Data.a 255;			blue
Data.a 0;			reserved (0)
; Icon Data III		Bitmaps
Data.a 0;...		And-Bitmap (z.B. 20x20x4 Bytes)
Data.l 0;...		Xor-Bitmap (z.B. 20x4* Bytes) *) 8 Pixel pro Byte > 20/8=2.5 > 4, weil pro Zeile auf 32 Bit aufgerundet wird


Re: Difference between icons and PNGs on gadgets

Posted: Thu Jun 29, 2023 9:43 pm
by HeX0R
or let them scroll :mrgreen:
(Not sure, if that stone old code still works, though)

Re: Difference between icons and PNGs on gadgets

Posted: Thu Jun 29, 2023 10:06 pm
by jacdelad
Nah, it's ok. I included the PNGs now, they look better when disabled. I would prefer to have them a bit faded, but that's just my liking (also I know, I can do it myself and create a second image that is used when the button is disabled or use a canvas).
I was just curious and my question was answered.