0

I am pulling an image from the web and adding it to a FixedDocument page. The image that I am pulling has dimension size of 1200px X 1500px. However in the FixedDocument the image appears as a small thumbnail (please see the screen grab).

Given below is the code snippet.

FixedDocument fd = new FixedDocument();

BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.UriSource = new Uri(@"http://www.example.com/image.jpg", UriKind.Absolute);
bi.EndInit();
Image i = new Image();
i.Source = bi;

FixedPage fixedPage = new FixedPage();
fixedPage.Children.Add(i);                

PageContent pageContent = new PageContent();
(pageContent as IAddChild).AddChild(fixedPage);
fd.Pages.Add(pageContent);

I need the image to appear as per its dimensions and not as a thumbnail. Please can someone let me know what needs to be done to show the image as per its size?

Many thanks.

enter image description here

H.B.
  • 166,899
  • 29
  • 327
  • 400
Anand Shah
  • 14,575
  • 16
  • 72
  • 110
  • Your code works fine for me with [this](http://upload.wikimedia.org/wikipedia/commons/c/cd/RathausBremen-01-2.jpg) large image. You could cross check the image size in a [BitmapSource.DownloadCompleted](http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapsource.downloadcompleted.aspx) event handler to see if you got what you wanted. – Clemens Feb 29 '12 at 12:06
  • @Clemens : Thank you. Please put your comment as an answer and I'll accept it. As you pointed upon inspecting the height and width in the DownloadCompleted event handler revealed the problem. The height and width were showing as 150px X 225px respectively. Why would that be? The image from your link in your comment opens up to its perfect size, is it a server issue? – Anand Shah Feb 29 '12 at 13:36

3 Answers3

2

Your code works fine for me with this large image.

You could cross check the image size in a BitmapSource.DownloadCompleted event handler to see if you got what you wanted.

Although, i would have no explanation why the image size would differ from what you expect. As far as i know JPEG image files can contain thumbnail images for fast preview. Perhaps your server is delivering such a thumbnail?

Clemens
  • 123,504
  • 12
  • 155
  • 268
0

Try setting

i.Height = bi.PixelHeight;
i.Width = bi.PixelWidth;

That should re-size i according to the the image pixels.

Picrofo Software
  • 5,475
  • 3
  • 23
  • 37
Khairi
  • 1
0

You can add a ViewBox and put the image inside it. ViewBox size should be the size of your doc minus any margins needed

AsitK
  • 651
  • 1
  • 4
  • 14