We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

How to calculate ScaleTransform for an image

How to calculate ScaleTransform for an image, while setting ScaleTransform for a pdf page?
pdfPage.Graphics.ScaleTransform(.80f, .80f)
Thanks,
Tanmaya

3 Replies

PH Praveenkumar H Syncfusion Team September 18, 2013 03:59 AM UTC

Hi Tanmaya,

Thanks for using syncfusion products,

We can apply scale transformation of image in the following way.

PdfImage  img = PdfBitmap.FromFile("../../Data/image.jpg");
page.Graphics.ScaleTransform(0.1F, 0.1F);
page.Graphics.DrawImage(img, new PointF(0, 0));
page.Graphics.Restore();

Once we set the scale transformation to the page it will applicable to the element which is drawn into the page. after we can restore the graphics using Restore() function.

The sample project is attached for your reference.

With Regards,
Praveen





ScaleTransformSample_f32bb0c7.zip


TM Tanmaya Mohanty September 18, 2013 06:24 AM UTC

Hi Praveen,

Thanks for the reply. I understand the way a need to set the ScaleTransform. but my question is depending on my image size i need to set the value for ScaleTransform. How do i calculate that value? i have a code that dynamically generates images with different size (different width and height). i can't set a fix value for ScaleTransform, so i need to calculate this value on the fly.

Thanks,
Tanmaya


PH Praveenkumar H Syncfusion Team September 25, 2013 03:54 AM UTC

Hi Tanmaya,

Thanks for using Syncfusion products,

 We are able to set the image bounds manually, it automatically scales the image to its dimension internally.

The sample code snippet is given below.

page.Graphics.DrawImage(img,0,0,100,100);

The sample project is attached for your reference.

 AddingImage.zip

Please let us know if you need any further assistance.

With Regards,

Praveen

 


Loader.
Live Chat Icon For mobile
Up arrow icon