[Gtk-sharp-list] High resolution image on a PdfSurface

David Cantin david_cantin at videotron.ca
Sun May 27 10:30:04 EDT 2007


I think I've found the answer myself by simply using the Cairo.Matrix
property of the Cairo.Context...




// (8,5 x 11) x 72dpi = (612 x 792)
PdfSurface pdfSurface = new PdfSurface("/home/me/Desktop/test.pdf", 612,
792);
pdfSurface.SetFallbackResolution(300.0, 300.0);

Cairo.Context cc = new Cairo.Context(pdfSurface);

Cairo.Matrix m = cc.Matrix;
// (72 / 300) = 0.24
m.Scale(0.24, 0.24);
cc.Matrix = m;

// All measures are divided by 0.24
cc.Rectangle(new PointD(312.5, 416.6), 2000, 1500);

// "/home/me/Desktop/test.jpg" is a 2304x1728 picture
Pixbuf pixbuf = new Pixbuf("/home/me/Desktop/test.jpg");
Gdk.CairoHelper.SetSourcePixbuf(cc, pixbuf.ScaleSimple(2000, 1500,
InterpType.Hyper), 312.5, 416.6);

cc.Fill();

pdfSurface.Finish();


Le dimanche 27 mai 2007 à 02:00 -0400, David Cantin a écrit :

> Hi, the following code is working great except that I don't known how
> I can render a image on my PdfSurface at good resolution (say 300
> dpi).
> 
> 
> // (8,5 x 11) x 72dpi = (612 x 792)
> PdfSurface pdfSurface = new PdfSurface("/home/me/Desktop/test.pdf",
> 612, 792);
> pdfSurface.SetFallbackResolution(300.0, 300.0);
> 
> Cairo.Context cc = new Cairo.Context(pdfSurface);
> 
> cc.Rectangle(new PointD(75, 100), 480, 360);
> 
> // "/home/me/Desktop/test.jpg" is a 2304x1728 picture
> Pixbuf pixbuf = new Pixbuf("/home/me/Desktop/test.jpg");
> Gdk.CairoHelper.SetSourcePixbuf(cc, pixbuf.ScaleSimple(480, 360,
> InterpType.Hyper), 75, 100);
> 
> cc.Fill();
> 
> pdfSurface.Finish();
> 
> 
> 
> Maybe the problem is around the "Gdk.CairoHelper.SetSourcePixbuf" but
> i didn't find a way to pass higher resolution image to the method, if
> I put higher values on "pixbuf.ScaleSimple", the image get simply
> clipped...
> 
> I have also tried to change the initial size of the PdfSurface to
> 2550x3300 (see (8,5 x 11) x 300dpi = (2250 x 3300)) but this impact
> the paper size and it's not a good thing..
> 
> Should I use an other way to render an image to the surface ??
> 
> Any thought ??
> 
> David
> 
> 
> 
> 
> _______________________________________________
> Gtk-sharp-list maillist  -  Gtk-sharp-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/gtk-sharp-list/attachments/20070527/7f4b103f/attachment.html 


More information about the Gtk-sharp-list mailing list