#include Once "window9.bi"

Function Catch_imagea(Byval array As Ubyte Ptr) As Any Ptr
	
	Dim As GdkPixbufLoader Ptr loader
	
	Dim As Hbitmap im  , imNew
	
	Dim As GError Ptr er_
	
	Dim As Long iWidthIm, iHeightIm
	
	Dim As HDC cr
	
	Dim As cairo_surface_t Ptr surf    
	
	loader = gdk_pixbuf_loader_new ()
	
	gdk_pixbuf_loader_write (loader, array, UBoundIncBin(array), @er_)
	
	gdk_pixbuf_loader_close(loader,@er_)
	
	im = gdk_pixbuf_loader_get_pixbuf (loader)	   
	
	If gdk_pixbuf_get_has_alpha (im) = 0 Then	
		
		iWidthIm = gdk_pixbuf_get_width(im)
		
		iHeightIm = gdk_pixbuf_get_height(im)
		
		If 	iWidthIm = 0 Orelse iHeightIm = 0 Then Return 0
		
		imNew =  gdk_pixbuf_new (GDK_COLORSPACE_RGB, True, 8 , iWidthIm, iHeightIm)
		
		gdk_pixbuf_fill(imNew , &hFFFFFF00)
		
		surf = cairo_image_surface_create_for_data(gdk_pixbuf_get_pixels(imNew),CAIRO_FORMAT_ARGB32,iWidthIm,iHeightIm,gdk_pixbuf_get_rowstride(imNew))
		
		cr = cairo_create (surf)
		
		gdk_cairo_set_source_pixbuf(cr, im, 0, 0)
		
		cairo_paint(cr)
		
		cairo_destroy (cr)
		
		cairo_surface_destroy(surf)	
		
		g_object_unref(im)	
		
		Return imNew
		
	Else
		
		Return im
		
	Endif
	
End Function