Forum > Graphics

PGdkPixbuf from stream

(1/1)

mrdebug:
Does anybody knows how to create a new PGdkPixbuf from byte array or stream? There isn't gdk_pixbuf_new_from_stream gtk2 function in pfc.

theo:
What do you want to achieve?

mrdebug:
I'm writing a client for a videoserver. The Lcl components are too slow to show a jpeg sequence. To obtain the fastest refresh I'm writing a gtk2 form. I can read a jpeg image from file but I don't understand how can I create a PGdkPixbuf from an byte array or stream. The gdk_pixbuf_new_from_stream function does not exists in pfc.

theo:
You could try sth like this:


--- Code: ---  {$ifdef LCLGtk2}
   Cairo, gdk2, gtkDef, gtkProc,
  {$endif}
   Graphics, Classes, SysUtils, opbitmap;


{$ifdef LCLGtk2}
function gdk_cairo_create(drawable: PGdkDrawable): Pcairo_t; cdecl; external gdklib;

procedure OpBitmapPaint32(Canvas:Graphics.TCanvas; Bmp: TOpBitmap; X, Y: integer);
var cr: Pcairo_t;
  surface: Pcairo_surface_t;
begin
  Bmp.PixelFormat := pf32bit;
  cr := gdk_cairo_create(TGtkDeviceContext(Canvas.Handle).Drawable);
  surface := cairo_image_surface_create_for_data(Bmp.ScanLine[0], CAIRO_FORMAT_RGB24, Bmp.Width, Bmp.Height, Bmp.Data.LineLength);
  if surface <> nil then
  begin
    cairo_set_source_surface(cr, surface, X, Y);
    cairo_paint(cr);
  end;
  cairo_destroy(cr);
  cairo_surface_destroy(surface);
end;
{$endif}


--- End code ---

Where OpBitmap.ScanLine[0] points to an array of 32bit ARGB.

Navigation

[0] Message Index

Go to full version