<br> As per my understanding there is no jpeg image decoder in cairo. only png surfaces were supported.<div>-vicky<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Message: 1<br>
Date: Thu, 5 Jan 2012 18:35:51 -0800<br>
From: Jeffrey Britton &lt;<a href="mailto:jeffb0098@gmail.com">jeffb0098@gmail.com</a>&gt;<br>
Subject: [cairo] Trouble displaying a jpeg image<br>
To: <a href="mailto:cairo@cairographics.org">cairo@cairographics.org</a><br>
Message-ID:<br>
        &lt;<a href="mailto:CAJTKU_h6YF6e-5uG_VP5PgdTaryxmT6zvKaKiLe54cDuGvy9hg@mail.gmail.com">CAJTKU_h6YF6e-5uG_VP5PgdTaryxmT6zvKaKiLe54cDuGvy9hg@mail.gmail.com</a>&gt;<br>
Content-Type: text/plain; charset=&quot;iso-8859-1&quot;<br>
<br>
I am trying to read a jpg from file and display it.<br>
I am using Python with pyCairo.<br>
<br>
I have the following code that works with some help from PIL, but it is<br>
slow.<br>
I feel that there must be a more direct route.<br>
<br>
There is an example at this link:  <a href="http://cairographics.org/pythoncairopil/" target="_blank">http://cairographics.org/pythoncairopil/</a><br>
but it does not work.<br>
<br>
<br>
img = Image.open(&#39;image.jpg&#39;)<br>
<br>
# The next 3 lines are to get the data to pass to Image.frombuffer<br>
# I need to convert rgb to bgra.<br>
l = [struct.pack(&#39;BBBB&#39;, b, g, r, 0xFF) for (r,g,b) in img.getdata()]<br>
<br>
# runs over whole image to convert to string<br>
s = string.join(l, &#39;&#39;)<br>
<br>
# runs over whole image again to get a writable buffer<br>
data = array.array(&#39;B&#39;, s)<br>
<br>
im1 = Image.frombuffer(&quot;RGBA&quot;, img.size, data, &quot;raw&quot;, &quot;RGBA&quot;, 0, 1)<br>
<br>
# runs over whole image twice<br>
self.img = array.array(&#39;B&#39;, im1.tostring())<br>
<br>
stride = cairo.ImageSurface.format_stride_for_width(cairo.FORMAT_ARGB32,<br>
self.width())<br>
self.img_surface = cairo.ImageSurface.create_for_data (self.img,<br>
cairo.FORMAT_ARGB32, self.width(), self.height(), stride)<br>
<br>
Yikes that is bad.<br>
<br>
Once I have the surface, then I do<br>
ctx.set_source_surface(surface, self.x, self.y)<br>
make_rectangle_path(ctx, self.x, self.y, self.width(), self.height())<br>
ctx.fill()<br>
<br>
Help!<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: &lt;<a href="http://lists.cairographics.org/archives/cairo/attachments/20120105/0b6018f2/attachment.htm" target="_blank">http://lists.cairographics.org/archives/cairo/attachments/20120105/0b6018f2/attachment.htm</a>&gt;<br>

<br></blockquote></div></div>