differences between text/imagedata of image in LC6/8
Mark Waddingham
mark at livecode.com
Fri Mar 24 06:58:28 EDT 2017
Hi Tiemo,
> in an old program I obviously tried to be very technically over correct
> when
> copying an image and did:
>
> 1. set the imagedata of img 2 to the imagedata of img 1
>
> This worked up to LC 6.7. In LC8/9 I get a corrupted image (black and
> stripes) in the target image.
The imageData of an image is the extracted color values for the pixels
in the
image. Specifically, it is a sequence of bytes with each pixel
represented as
xRGB. These are the bytes which are applied to the screen when the image
is
rendered and does not include any alpha data (which is specified using
the
alphaData property). To set the imageData you need to set the width and
height
of the field first.
> What works in LC8/9 is
>
> 2. set the text of img 2 to the text of img 1
>
> and
>
> 3. put img 1 into img 2
Both of these do the same thing - (3) is short hand for (1).
The 'text' of an image is the original image data from a format such as
PNG, GIF etc.
i.e. the content of a PNG file or GIF file.
> What is the correct syntax today? Is solution 2 and 3 the same and just
> an
> alias (what it seems to me) or are there differences in details I do
> not
> see?
In general, (2) or (3) is better than (1) as (1) is considered an 'image
editing'
operation and as such will cause a recompression of the data in some
fashion. Also
(2) and (3) will automatically set the size, and alpha channel of the
image appropriately.
> And is there any explanation why the upward compatibility of solution 1
> is
> broken?
If there is a difference here then it is a bug - although please do
check that the width/height of the image is the same, and also transfer
across alphaData too.
I'd recommend using (2) or (3) - or, indeed, using referenced files
instead. The engine
will automatically cache referenced images and share the underlying
decompressed data.
i.e.
set the filename of image 1 to "foo"
set the filename of image 2 to "foo"
Will first resolve "foo" as an absolute path, load that image file into
a cache if not
already present and attach the decompressed image data to the image
object. Then, when
the second image's filename is set, it will find the image is already in
the cache and
just use the decompressed image data attached to that file in the cache.
i.e. The two images share the same pixel data in memory.
Warmest Regards,
Mark.
--
Mark Waddingham ~ mark at livecode.com ~ http://www.livecode.com/
LiveCode: Everyone can create apps
More information about the use-livecode
mailing list