grumble. I feel betrayed by …
The code I’ve had has never thrown an NOE. I’ve ran this function thousands of times and it never failed. Now that I put it in its own project, I have for the constructor for graphics.DrawPicture a negative number and it’s slways been there. Grumble
I’m posting this because I feel embarrassed. I try to figure it out.
The call for my function ScalePicture is
AbtMWXIcon.Image = App.ScalePicture( xImgPic, AbtMWXIcon.Width, AbtMWXIcon.Height)
AbtMWXIcon is the future image.
The line with the NOE is
p2.Graphics.DrawPicture PictureToScale, (Availablewidth-neww)\2, (Availableheight-newh)\2, neww, newh, 0, 0, w, h
The function:
ScalePicture (PictureToScale As Picture, Availablewidth As Integer, Availableheight As Integer)
// Now Scale the image
try
'Var p2 as Picture
Var d as double
Var w, h, neww, newh as integer
w = PictureToScale.width
h = PictureToScale.height
d = min( Availablewidth/w,Availableheight/h ) // Calculate the factor with which to scale
neww = w*d // the new width of the picture
newh = h*d // the new height of the picture
Var p2 as Picture = new Picture( Availablewidth, Availableheight, PictureToScale.Depth )
p2.Graphics.DrawPicture PictureToScale, (Availablewidth-neww)\2, (Availableheight-newh)\2, neww, newh, 0, 0, w, h
return p2
Catch err As OutOfMemoryException
#If TargetWindows Then
bmsg = New BoxMssage( 0, "Insufficient memory to draw the picture!", "", CurrentMethodName )
#Else
MessageBox("Insufficient memory to draw the picture!")
#EndIf
Return Nil
Catch err As NilObjectException
#If TargetWindows Then
bmsg = New BoxMssage( 0, "The Picture Cannot be Used Because of " + err.ErrorNumber.ToText, "Picture", CurrentMethodName )
#Else
MessageBox("The Picture Cannot be Used Because of " + err.ErrorNumber.ToText)
#EndIf
Return Nil
Catch err As UnsupportedFormatException
#If TargetWindows Then
bmsg = New BoxMssage( 0, "The Picture Cannot be Used Because of " + err.ErrorNumber.ToText, "Picture", CurrentMethodName )
#Else
MessageBox("The Picture Cannot be Used Because of ")
#EndIf
Return Nil
End Try
//Graphics.DrawPicture(Image As Picture, x As Double, y As Double [,destWidth As Double ] [, destHeight As Double ]
// [, sourceX As Double ] [, sourceY As Double ] [, sourceWidth As Double ] [, sourceHeight As Double])