Cropping an image

Monte Goulding monte at appisle.net
Fri Jun 1 00:27:42 EDT 2018


This reminds me I was looking at this stuff the other day and it’s really not a big job to add a pixelData property that is ARGB instead of the xRGB we have for imageData which would reduce the data you are dealing with if you want to set the alpha at the same time.

Good community contribution I’d suggest (that doesn’t mean you have to do it today Brian ;-)

Cheers

Monte

> On 1 Jun 2018, at 2:07 pm, Ralph DiMola via use-livecode <use-livecode at lists.runrev.com> wrote:
> 
> 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
> 
> 
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list