PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

XImage from FileStream
https://forum.pdfsharp.net/viewtopic.php?f=2&t=472
Page 1 of 1

Author:  phil.netring [ Wed Sep 10, 2008 3:03 pm ]
Post subject:  XImage from FileStream

Hi Folks,

I've noticed a few people ask the question, How do I create a XImage from a FileStream? So here is the answer;

You can not create a XImage directly from the FileStream but you can create an XImage from a System.Drawing.Image (GDI+ Image) using the XImage.FromGdiPlusImage(Image) static method.

So, use System.Drawing.Image.FromStream(imageStream) to create your GDI+ Image object, and then use Ximage.FromGdiPlusImage(gdiPlusImage) to create you're XImage.

Example;
Code:
System.IO.Stream imageStream = System.Net.WebRequest.Create(imagePath).GetResponse().GetResponseStream();                  
System.Drawing.Image systemImage = System.Drawing.Image.FromStream(imageStream);                     
XImage xImage = XImage.FromGdiPlusImage(systemImage);   


Hope this helps someone,
P.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/