Click here to Skip to main content
15,311,561 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

i use WPF to render image in XPSreport.when i render the image it should
maintain orginal aspect ratio.now the image is blurred .iam attaching the
code can any one correct me it is bit urgent.

Bitmap bitmap = Resources.Logo;//loading from resource
      BitmapSource imgSource = ConvertToBitmapSource(bitmap);//converting to WPF format
     drawingContext.DrawImage(imgSource,new Rect(Sizes.Gutter + 10,Sizes.Margin + 10,300,30));

 public static BitmapSource ConvertToBitmapSource(Bitmap bitmap) {
     IntPtr hBitmap = bitmap.GetHbitmap();
     return Imaging.CreateBitmapSourceFromHBitmap(hBitmap,IntPtr.Zero,Int32Rect.Empty,BitmapSizeOptions.FromEmptyOptions());
     }
Posted
Updated 1-Jan-18 18:54pm

hi

In the above code we have to take just an Image Control
for that there is a property called "Stretch" set the value as "Uniform"
here is the sample code

Image img=new Image();
img.Stretch = Stretch.Uniform;
BitmapImage bitImg = new BitmapImage(new Uri(Imagefilepath, UriKind.RelativeOrAbsolute));
img.Source = bitImg;

then add Image to any of the Panel Control, Then it will Work Fine.....

reagrds,
Md.Siraz
   
Comments
sajithnet 31-Jan-12 22:29pm
   
many thanks for ur support but problem still exists
sirazuddin 1-Feb-12 6:11am
   
Have you Romove all your code or can you send me the modify code
Hi can you help me with how to set the aspect ratio if I am using an image element.
   
Comments
Graeme_Grant 2-Jan-18 3:27am
   
Please start a new question rather than post "a question as a solution" to a 5+ year old question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900