This project has moved and is read-only. For the latest updates, please go here.

Creating Images/Pictures from a stream

Jun 14, 2012 at 4:42 PM
Edited Jun 14, 2012 at 4:43 PM


I am trying to insert a System.Drawings.Bitmap into my Document. 


What i do with the Bitmap is:

MemoryStream ms = new MemoryStream();

bitmap.Save(ms, ImageFormat.Png);

Image img1 = doc.AddImage(ms);

Picture pic1 = img1.CreatePicture();



I get an argumentException when running the InsertPicture().

at System.Drawing.Image.FromStream(Stream streamBoolean useEmbeddedColorManagementBoolean validateImageData)
at System.Drawing.Image.FromStream(Stream stream)
at Novacode.Paragraph.CreatePicture(DocX documentString idString nameString descr)
at Novacode.Image.CreatePicture()

If someone had this issue before, id gladly like to find out what im supposed to do to insert a picture. Thank you =)

EDIT: I have saved the Bitmap into a file, and the picture i wanted was the expected one.

Jul 2, 2012 at 12:00 PM

Try to add an 


ms.Position = 0;


before the AddImage call.