Image.GrabImage() bug + fix

Monkey Forums/Monkey Bug Reports/Image.GrabImage() bug + fix

Auburn(Posted 2012) [#1]
When using GrabImage and grabbing multiple rows of frames if X value is greater than 0 all rows after the first start their row at 0 X regardless of what was set for the X value in the GrabImage function.

Example:
image.png(550x300)

[monkeycode]gfx = LoadImage( "image.png" )
textures = gfx.GrabImage( 50, 0, 100, 100, 15 )[/monkeycode]

The first row of frames are grabbed fine but the 2 following start at x=0 so all the frames are offset by 50 pixels

Fix:
[monkeycode]Method Grab:Image( x,y,iwidth,iheight,nframes,iflags,source:Image )
Self.source=source
surface=source.surface

width=iwidth
height=iheight

frames=New Frame[nframes]

Local ix:=x,iy:=y

For Local i=0 Until nframes
If ix+width>source.width
ix=x '<------------ from ix=0
iy+=height
Endif
If ix+width>source.width Or iy+height>source.height
Error "Image frame outside surface"
Endif
frames[i]=New Frame( ix+source.frames[0].x,iy+source.frames[0].y )
ix+=width
Next

ApplyFlags iflags
Return Self
End[/monkeycode]