Save image to sharedObject
How do I save the image to SharedObject
? I use SharedObject
to save application state, it works well for text object and UIComponent
well, but keeps the problem Image
create.It does not throw errors.
userdiagram.imageData = zorder.getItemAt(i) as mx.controls.Image
userdiagram.x = (zorder.getItemAt(i)).x;
userdiagram.y = (zorder.getItemAt(i) ).y;
userdiagram.height = (zorder.getItemAt(i)).height
userdiagram.width = (zorder.getItemAt(i)).width
here userdiagram is a class and imageData is an image type variable.
source to share
I keep the link "Image as a sentence" Abhinava:
var data:BitmapData = new BitmapData((zorder.getItemAt(i) as mx.controls.Image).width, (zorder.getItemAt(i) as mx.controls.Image).height);
data.draw((zorder.getItemAt(i) as mx.controls.Image));
var encoder:JPGEncoder = new JPGEncoder();
var bytes:ByteArray = encoder.encode(data);
userdiagram.x = (zorder.getItemAt(i)).x;
userdiagram.y = (zorder.getItemAt(i) ).y;
userdiagram.height = (zorder.getItemAt(i)).height
userdiagram.width = (zorder.getItemAt(i)).width
userdiagram.rotation = (zorder.getItemAt(i)).rotation
userdiagram.bytes = bytes;
saveState.addItem(userdiagram)
But when I get an image from sharedObject
create an object of type image and use the following code:
var v:Object = _saveIn.data.value1.readObject();
p.source = (v as ArrayList).getItemAt(i).bytes;
here p is the image class object and (v as ArrayList).getItemAt(i)
is the byte byte location.
source to share
You need to use byteArray to store the image in a sharedObject.
You can read more about this here: http://www.kirupa.com/forum/showthread.php?306972-Saving-bitmaps-to-a-shared-object
source to share