# Scaling image

**URL:** <https://forum.xojo.com/t/scaling-image/35625>\
**Category:** Getting Started\
**Created:** [January 20, 2017, 8:01pm UTC](https://forum.xojo.com/t/scaling-image/35625 "2017-01-20T20:01:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim\_Turner](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_turner/32/776_2.png) [@Tim\_Turner](https://forum.xojo.com/u/Tim_Turner)\
**Post date:** [January 20, 2017, 8:01pm UTC](https://forum.xojo.com/t/scaling-image/35625/1 "2017-01-20T20:01:27Z")

</div>

When drawing an image to a page on the printout… my image is huge compared to the page.

I have tried to scale it down but now it’s too small.

How can I scale an image to exactly fit the width of the page with no margins.  
If I can do that than I can play with it to position it.

---

<div class="post-metadata">

**Author:** ![DaveS](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/848f3c/32.png) [@DaveS](https://forum.xojo.com/u/DaveS)\
**Post date:** [January 20, 2017, 8:20pm UTC](https://forum.xojo.com/t/scaling-image/35625/2 "2017-01-20T20:20:33Z")

</div>

```auto
dim scale as double=(g.width/p.width) // assumes HEIGHT of picture is less than WIDTH
dim h=scale*p.height
g.drawpicture p,0,0,g.width,h, 0,0,p.width,p.height
```

off the top of my head… but I think that would do it  
G=graphics context of printer page  
P=picture object you wish to draw

---

<div class="post-metadata">

**Author:** ![Jean-Yves\_Pochez](https://forum.xojo.com/user_avatar/forum.xojo.com/jean-yves_pochez/32/21769_2.png) [@Jean-Yves\_Pochez](https://forum.xojo.com/u/Jean-Yves_Pochez)\
**Post date:** [January 20, 2017, 9:10pm UTC](https://forum.xojo.com/t/scaling-image/35625/3 "2017-01-20T21:10:24Z")

</div>

this works for any width/height (except zero…)  
beware where are/arent the dots …

`dim gheight as Integer = g.Width/p.Width*p.Height
dim gwidth as Integer = g.Height/p.Height*p.Width
if g.Width>g.Height then
	g.DrawPicture p, 0, 0, gwidth, g.Height, 0, 0, p.Width, p.Height
else
	g.DrawPicture p, 0, 0, g.Width, gheight, 0, 0, p.Width, p.Height
end if
`

---

<div class="post-metadata">

**Author:** ![Tim\_Turner](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_turner/32/776_2.png) [@Tim\_Turner](https://forum.xojo.com/u/Tim_Turner)\
**Post date:** [January 25, 2017, 3:16pm UTC](https://forum.xojo.com/t/scaling-image/35625/4 "2017-01-25T15:16:40Z")

</div>

Thanks Dave S and Jean-Yves (merci beaucoup)…got it working.

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 6:37pm UTC](https://forum.xojo.com/t/scaling-image/35625/5 "2020-10-29T18:37:19Z")

</div>


