Recent

Author Topic: PGdkPixbuf from stream  (Read 4024 times)

mrdebug

  • Full Member
  • ***
  • Posts: 158
PGdkPixbuf from stream
« on: May 20, 2010, 05:20:04 pm »
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

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1891
Re: PGdkPixbuf from stream
« Reply #1 on: May 20, 2010, 06:25:01 pm »
What do you want to achieve?

mrdebug

  • Full Member
  • ***
  • Posts: 158
Re: PGdkPixbuf from stream
« Reply #2 on: May 20, 2010, 06:39:37 pm »
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

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1891
Re: PGdkPixbuf from stream
« Reply #3 on: May 20, 2010, 07:07:44 pm »
You could try sth like this:

Code: [Select]
  {$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}


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

 

TinyPortal © 2005-2018