I have 10 System.Drawing.Image. I need to add them to FixedDocument. I tried the code below and a fixed document is transmitted with all 10 pages consisting of only the first image.
FixedDocument doc = new FixedDocument();
BitmapSource[] bmaps = new BitmapSource[10];
System.Drawing.Image[] drawingimages =
for (int i = 0; i < 10; i++)
{
Page currentPage = this.Pages[i];
System.Drawing.Image im = drawingimages[i];
im.Save(i + ".png");
Stream ms = new MemoryStream();
im.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
var decoder = BitmapDecoder.Create(ms, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnDemand);
ImageSource imgsource = decoder.Frames[0];
bmaps[i] = imgsource as BitmapSource;
}
foreach (BitmapSource b in bmaps)
{
PageContent page = new PageContent();
FixedPage fixedPage = CreateOneFixedPage(b);
((IAddChild)page).AddChild(fixedPage);
doc.Pages.Add(page);
}
CreateOneFixedPage Method
private FixedPage CreateOneFixedPage(BitmapSource img)
{
FixedPage f = new FixedPage();
Image anImage = new Image();
anImage.BeginInit();
anImage.Source = img;
anImage.EndInit();
f.Children.Add(anImage);
return f;
}
When I try to save System.Drawing.Imageto a local drive, all 10 images will be saved correctly. What is the error in my code here?
source
share