The follow up of same posts
A exemple stack is available in RevOnLine with name "minrectofpaint"
Thank to Jan and Bernd for support
RectOfPaintNoTransparent function return the minimum rectangle of a paint image (the first pixel no transparent at TopLeft,TopRight,BottomRight and BottomLeft
Code: Select all
function RectOfPaintNoTransparent pImage
put the Topleft of Image pImage into LeTLim
put TopOfPaintAlpha(pImage) into rTop
put BotOfPaintAlpha(pImage) into rBot
put LeftOfPaintAlpha(pImage) into rLeft
put RightOfPaintAlpha(pImage) into rRight
put rLeft,rTop,rRight,rBot into LaR
add item 1 of LeTLim to item 1 of LaR
add item 2 of LeTLim to item 2 of LaR
add item 1 of LeTLim to item 3 of LaR
add item 2 of LeTLim to item 4 of LaR
return LaR
end RectOfPaintNoTransparent
function TopOfPaintAlpha pImage -- return the top of a paint image (the first pixel no transparent at top)
put the alphadata of image pImage into tAlphaData
put the width of image pImage into tWidth
put the height of image pImage into tHeight
put empty into tTopBuffer
put 1 into tByteIndex
repeat with tRow = 1 to tHeight
repeat with tColumn = 1 to tWidth
put charToNum(char tByteIndex of tAlphaData) into tPixelData
if tPixelData is not 0 then
put tRow-1 into tTopBuffer
return tTopBuffer
end if
add 1 to tByteIndex
end repeat
end repeat
return empty
end TopOfPaintAlpha
function RightOfPaintAlpha pImage -- return the right of a paint image (the last pixel no transparent at right)
put the alphadata of image pImage into tAlphaData
put the width of image pImage into tWidth
put the height of image pImage into tHeight
put empty into tTopBuffer
put the left of image pImage into laLeftDep
put 1 into tByteIndex
put 1 into tColumn
repeat with tColumn = tWidth down to 1
repeat with tRow = 1 to tHeight
put (tRow*tWidth)-tWidth+tColumn into tByteIndex
put charToNum(char tByteIndex of tAlphaData) into tPixelData
if tPixelData is not 0 then
put tColumn+1 into tTopBuffer
return tTopBuffer
end if
end repeat
end repeat
return empty
end RightOfPaintAlpha
function BotOfPaintAlpha pImage -- return the bot of a paint image (the last pixel no transparent at bot)
put the alphadata of image pImage into tAlphaData
put the width of image pImage into tWidth
put the height of image pImage into tHeight
put empty into tTopBuffer
put tWidth*tHeight into tByteIndex
repeat with tRow = tHeight down to 1
repeat with tColumn = tWidth down to 1
put charToNum(char tByteIndex of tAlphaData) into tPixelData
if tPixelData is not 0 then
put tRow+1 into tTopBuffer
return tTopBuffer
end if
subtract 1 from tByteIndex
end repeat
end repeat
return empty
end BotOfPaintAlpha
function LeftOfPaintAlpha pImage -- return the left of a paint image (the first pixel no transparent at left)
put the alphadata of image pImage into tAlphaData
put the width of image pImage into tWidth
put the height of image pImage into tHeight
put empty into tTopBuffer
put the left of image pImage into laLeftDep
put 1 into tByteIndex
put 1 into tColumn
repeat with tColumn = 1 to tWidth
repeat with tRow = 1 to tHeight
put (tRow*tWidth)-tWidth+tColumn into tByteIndex
put charToNum(char tByteIndex of tAlphaData) into tPixelData
if tPixelData is not 0 then
put tColumn-1 into tTopBuffer
return tTopBuffer
end if
end repeat
end repeat
return empty
end LeftOfPaintAlpha
Jean-Marc