Resize picture and save

I would like to resize a picture and save. I know how to resize a picture to a canvas. But not sure how to assign a canvas backdrop to a picture. I saw lot of examples on how to go from a picture to a canvas. And the other way around ?

Any suggestions on how to resize a picture easily ?

It’s not too dissimilar.

Create a new picture at the desired size, then draw the old picture into the new picture. The code below is untested, but should be enough to start with.

function resizePicture( inPicture as picture, newWidth as integer, newHeight as integer ) as picture
Dim r as new picture( inWidth, inHeight )
Dim g as graphics = r.graphics
g.drawpicture inPicture, 0, 0, inWidth, inHeight, 0, 0, inPicture.width, inPicture.height

return r
End function

Or better:

function resizePicture( inPicture as picture, newWidth as integer, newHeight as integer ) as picture Dim r as new picture( newWidth, newHeight ) r.drawpicture inPicture, 0, 0, newWidth, newHeight, 0, 0, inPicture.width, inPicture.heigh return r End function

Not sure why you ise the extra g.graphics ? Any reason for this Sam?

Because the PICTURE object does not support DRAWPICTURE
only the GRAPHICS property of the PICTURE does

OK my mistake: it should be

function resizePicture( inPicture as picture, newWidth as integer, newHeight as integer ) as picture Dim r as new picture( newWidth, newHeight ) r.graphics.drawpicture inPicture, 0, 0, newWidth, newHeight, 0, 0, inPicture.width, inPicture.height return r End function

Thank you gentlemen.

Keep in mind this method does not use anti-alliasing. So rescaling can have hard edges/visual artefacts.

If you have some spare cash left, try Studio Stable plugins. http://www.studiostable.com/graphics
They are very good.

Old habits die hard - I always have a separate graphics object, this way I can change the picture code without it affecting any of the graphics drawing code. It also enables me (should I choose to do so) to use the same function to draw directly to a canvas, window or picture.

But yes, it’s not required to be done this way.

I tried the code in this article to resize a picture object…
At runtime I get “Platform not supported” bug error on the declaration of the Dim r as new picture

[quote=27851:@Christoph De Vocht]Keep in mind this method does not use anti-alliasing. So rescaling can have hard edges/visual artefacts.

If you have some spare cash left, try Studio Stable plugins. http://www.studiostable.com/graphics
They are very good.[/quote]

I went to this site and the developer has discontinued these tools.

Apparently I have to use cocoa not carbon for this code to work. I am trying to scale the picture of a graph so that it fits larger onto a printed page. Right now its a bit small.

Carbon doesn’t support alpha channel pictures but it’s easy to make it a masked picture, just add ,32

dim r As new Picture(w, h, 32)

[quote=131958:@Tim Turner]function resizePicture( inPicture as picture, newWidth as integer, newHeight as integer ) as picture
Dim r as new picture( newWidth, newHeight )
r.graphics.drawpicture inPicture, 0, 0, newWidth, newHeight, 0, 0, inPicture.width, inPicture.height
return r
End function[/quote]

function resizePicture( inPicture as picture, newWidth as integer, newHeight as integer ) as picture Dim r as new picture( newWidth, newHeight,32 ) r.graphics.drawpicture inPicture, 0, 0, newWidth, newHeight, 0, 0, inPicture.width, inPicture.height return r End function