[quote=134545:@Eugene Dakin]I created an example to show a work-around for resizing an image, and also to show that the picture.graphics.drawpicture method has an error (NilObjectException).
There are three canvas’s in this example:
- top left - a picture that is not resized - working as expected
- top right - a picture that is resized - using resizing of graphics parameter in Paint
- bottom left - Comment first line of code in Canvas3 Paint Event and uncomment session.graphics.drawpicture code and it should work, but gives a NilObject exception error
WebResize.zip
Should this work or am I missing something?[/quote]
Thank you. It works indeed if you directly use the picture dragged into the project, but the issue here is that we were trying to use a method that sizes the picture prior to display it to reduce the bulk.
Here is the method, taken from Christian’s kindness :
[code]Function ProportinalScaled(pic as Picture, Width as integer, Height as Integer) As Picture
// Calculate scale factor
dim faktor as Double = min( Height / Pic.Height, Width / Pic.Width)
// Calculate new size
dim w as integer = Pic.Width * faktor
dim h as integer = Pic.Height * faktor
// create new picture
dim NewPic as new Picture(w,h,32)
// draw picture in the new size
NewPic.Graphics.DrawPicture Pic, 0, 0, w, h, 0, 0, Pic.Width, Pic.Height
// return result
Return NewPic
End Function
[/code]
It returns a valid picture, easily displayed in a WebImageView, but which is not displayed in the Paint event of a webCanvas.
I added that method to your sample project, duplicated Canvas3 and in Canvas4, slightly modified your Paint code so it uses ProportinalScaled. No picture
Sub Paint(g as WebGraphics)
Session.pic = ProportinalScaled(ConvRPic,me.width,me.height) // This is where I modified the code
'Comment out the above line of code and un-comment one of the two lines of code below...
'session.pic.Graphics.DrawPicture(ConvRPic, 0,0,200,200,0,0,200,200) 'NilObjectException
'session.pic.Graphics.DrawPicture(ConvRPic,0,0) 'NilObjectException
Dim WP as new WebPicture
'Copy the picture into WebPicture
WP = session.Pic
'Draw the image at a screen location - not resized
g.DrawPicture(WP, 0, 0)
'Draw a black box around the canvas
g.ForeColor = RGB(0,0,0)
g.DrawRect(0,0,me.Width, me.Height)
End Sub