[cairo] Is posible create a png surface from a png buffer read from a zip file?

Elmar Haneke elmar at haneke.de
Fri Nov 6 06:37:31 PST 2015


> I found thecairo_image_surface_create_from_png_stream
> <http://cairographics.org/manual/cairo-PNG-Support.html#cairo-image-surface-create-from-png-stream> ()
> is hard to manage and not references directly a buffer. It wil be easy
> to implement ?. Thanks for your comments.

This is the right procedure to do so wis some few lines of glue code.

For an pascal stream I use

   
sf:=cairo_image_surface_create_from_png_stream(@ReadFromStream,PNG_data);

there PNG_data is an stream containing PNG image.

the glue-code is rather simple:

function ReadFromStream(closure: Pointer; data: PByte; length:
LongWord):cairo_status_t; cdecl;
var
  Stream: TStream absolute closure;
begin
  if Stream.Read(data^, Length) = int64(Length) then
    result := CAIRO_STATUS_SUCCESS
  else
    result := CAIRO_STATUS_READ_ERROR;
end;

Hope that helps

Elmar



More information about the cairo mailing list