Cropping an image

Ralph DiMola rdimola at evergreeninfo.net
Fri Jun 1 00:07:25 EDT 2018


OK, Here's the deal. Although there is a byte for alpha in the z buffer (imagedata) it seems to be ignored. The alpha data is only in the alphadata property. You also must set the text property to empty before you set the new image(imagedata) and alpha data(alphadata).

This example just does a crop in the middle of y and pastes the remaining top and bottom together:

command CropMiddleOfImage pImageName, pMiddlePercentCrop
   --
   -- pImageName ==> LiveCode image control's name
   -- pMiddlePercentCrop ==> 0 to 100
   --
   local tImageData, tWidth, tHeight, tTop, tBottom, tNewImageData, tAlphaData, tNewAlphaData
   
   lock screen
   put the imagedata of image pImageName into tImageData
   put the alphadata of image pImageName into tAlphaData
   put the width of image pImageName into tWidth
   put the height of image pImageName into tHeight
   
   put pMiddlePercentCrop / 100 into pMiddlePercentCrop
   put trunc((tHeight - (tHeight * pMiddlePercentCrop)) / 2) into tTop
   put tTop into tBottom
   if not (((tHeight - (tHeight * pMiddlePercentCrop)) / 2) is an integer) then
      add 1 to tBottom
   end if
   
   put byte 1 to (tTop*4*tWidth) -1 of tImageData into tNewImageData
   put byte (the number of bytes of tImageData - (tBottom*4*tWidth)) to -1 of tImageData after tNewImageData
   put byte 1 to (tTop*tWidth) -1 of tAlphaData into tNewAlphaData
   put byte (the number of bytes of tAlphaData - (tBottom*tWidth)) to -1 of tAlphaData after tNewAlphaData
   
   set the height of image pImageName to tTop+tBottom
   set the width of image pImageName to tWidth
   set the text of image pImageName to empty
   set the imagedata of image pImageName to tNewImageData
   set the alphadata of image pImageName to tNewAlphaData
   
   unlock screen
   
end CropMiddleOfImage pImageName

Ralph DiMola
IT Director
Evergreen Information Services
rdimola at evergreeninfo.net






More information about the use-livecode mailing list