Xbasic

PNG_TO_BITMAP Function

Syntax

BMP as B = PNG_TO_BITMAP(B png_data[,C channel])

Arguments

BMP

The output BMP image.

png_data

The input PNG image.

channel

Character. Flags Optional. Default = "C"; "C" = Combined, "R" = RGB only, "A" = Alpha blend only

Description

Convert a png to a bitmap, optiona channel is default of (C)ombined, (R)gb only, (A)lpha blend only.

Discussion

The PNG_TO_BITMAP() function converts a PNG formatted image in memory to a Windows Bitmap (.BMP) formatted image.

Example

dim img as B
dim img2 as B
dim fptr as P
dim fptr2 as P
dim length as N
fptr = file.open("C:\NextYear.png",FILE_RW_EXCLUSIVE)
length = fptr.bytes_get()
img = fptr.readb(length)
img2 = png_to_bitmap(img)
fptr2 = file.create("c:\NextYear.bmp",FILE_RW_EXCLUSIVE)
fptr2.writeb(img2)
fptr2.close()
fptr.close()

Example of using the 'Combined' Flag

The png_to_bitmap function can be used with the 'C' flag, and to bitmap_to_png() to strip out the Alpha Channel. This is useful when you want to replace the Alpha Channel from a PNG file with the transparency with the background color specified in the PNG.

An example of this is printer drivers that generate 1.3 or ealier PDF format, which does not support transparency, and can lead to unexpected results like a completely blacked out rectangle where the image should be.

The expression to convert such a field is bitmap_to_png( png_to_bitmap(pngDataField,"C") ).

dim raw as b = ui_bitmap_png_save("$$application.alpha")
dim comb as b = bitmap_to_png( png_to_bitmap(raw,"C") )
ui_bitmap_png_load("png1",raw)
ui_bitmap_png_load("png2",comb)
ui_dlg_box("test","{image=png1} {image=png2}")

See Also