ImageData restore problems

FlexibleLearning.com admin at FlexibleLearning.com
Mon Sep 22 07:12:25 EDT 2014


Having wrestled with this for a long time, I post a solution for future
reference...


Situation
I have a large embedded image. I want to thumbnail it/rotate it/mess with
it, but be able to restore the original without loss of any original data.
How do we do this?


Solution
We need to save the original image's rect, text and imageData (alphaData and
maskData optional) perhaps most conveniently saved in a customPropertySet of
the image itself:

-- tObj: The long id of the image.
-- ImgBackup: The customPropertySet name.
-- savedImageRect, savedImageText,savedAlphaData, savedMaskData and
savedImageData: The array key names.

if the ImgBackup["savedImageData"] of tObj ="" then
   --| Save an original
   set the ImgBackup["savedImageRect"] of tObj to the rect of tObj
   set the ImgBackup["savedImageText"] of tObj to the text of tObj
   set the ImgBackup["savedAlphaData"] of tObj to the alphaData of tObj
   set the ImgBackup["savedMaskData"] of tObj to the maskData of tObj
   set the ImgBackup["savedImageData"] of tObj to the imageData of tObj
end if

To restore to the original state, first lock the image then restore the
rect, text, [alphaData and maskData] and imageData... Note that the order
things are done is important:

--| Restore the original
put the lockLoc of tObj into tLL
set the lockLoc of tObj to true
set the rect of tObj to the ImgBackup["savedImageRect"] of tObj
set the text of tObj to the ImgBackup["savedImageText"] of tObj
set the alphadata of tObj to the ImgBackup["savedAlphaData"] of tObj
set the maskdata of tObj to the ImgBackup["savedMaskData"] of tObj
set the imagedata of tObj to the ImgBackup["savedImageData"] of tObj
set the lockLoc of tObj to tLL

To optimise the image at any time and reduce the Kb needed, compact the
imageData and delete the backup. This is permanent and cannot be undone:

--| Optimise the image to its current display
set the imageData of tObj to the imageData of tObj
put the custompropertysets of tObj into tCPS
filter tCPS without "ImgBackup"
set the custompropertysets of tObj to tCPS



"Things are always easier with hindsight"

Hugh Senior
FLCo






More information about the use-livecode mailing list