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 ?
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
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?
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
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.
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
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.
[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