Copy link to clipboard
Copied
Hi, I'm trying to understand what is wrong with my code that I get this error.
var rect: Rectangle = new Rectangle(0,0,newText.width, newText.height);
var bitmapData: BitmapData = new BitmapData(newText.width, newText.height);
bitmapData.draw(newText);
var bitmap: Bitmap = new Bitmap(bitmapData);
var jpgEncoder: JPGEncoder = new JPGEncoder(90);
var byteArray: ByteArray = jpgEncoder.encode(bitmapData);
bitmapData.getPixels(rect);
//trace(" this bitmapData", byteArray);
//byteArray = PNGEncoder.encode(bitmapData);
var mySharedObject: SharedObject = SharedObject.getLocal("republicofcode");
mySharedObject.data.vwdinfo = byteArray;
mySharedObject.flush();
trace("this ughg", mySharedObject.data.vwdinfo);
// var mySharedObject: SharedObject = SharedObject.getLocal("republicofcode");
byteArray.position = 0;
trace(byteArray.position);
bitmapData.setPixels(rect,byteArray); // <-------------- this is the line that throws the error
var image: Bitmap = new Bitmap(bitmapData, "auto", true);
addChild(image);
is that an experiment or are you trying to accomplish something by ending up where you start?
and any encoding option (like jpgencoder) is likely to be problematic because of compression used to minimize the bytearray size. ie, you're going to hit an end of file error with any compression.
you should manually copy using getPixels, not an encoder:
var rect: Rectangle = new Rectangle(0,0,newText.width, newText.height);
var bitmapData: BitmapData = new BitmapData(rect.width, rect.height);
bitmapData.dr
...Copy link to clipboard
Copied
your target bitmap and rectangle are 'larger' than the bytearray.
Copy link to clipboard
Copied
Oh ok... thx
Would adding this line...
ByteArray = bitmapData. setpixels(rect);
Solve the issue... I'm not home at the moment to try anything out
Copy link to clipboard
Copied
what is it that you're trying to do?
Copy link to clipboard
Copied
Trying to convert a MC (newText) into a bitmap then to bytearray and back
Copy link to clipboard
Copied
is that an experiment or are you trying to accomplish something by ending up where you start?
and any encoding option (like jpgencoder) is likely to be problematic because of compression used to minimize the bytearray size. ie, you're going to hit an end of file error with any compression.
you should manually copy using getPixels, not an encoder:
var rect: Rectangle = new Rectangle(0,0,newText.width, newText.height);
var bitmapData: BitmapData = new BitmapData(rect.width, rect.height);
bitmapData.draw(newText);
var bitmap: Bitmap = new Bitmap(bitmapData);
var byteArray: ByteArray = bitmapData.getPixels(rect);
byteArray.position = 0;
bitmapData.setPixels(rect,byteArray); // <-------------- this is the line that throws the error
var image: Bitmap = new Bitmap(bitmapData, "auto", true);
addChild(image);
Copy link to clipboard
Copied
Ok i understand where you getting at. Because i will have a maximum of 42 possible mc i want to break into bytes in order to save them, then reconstruct one by one...it's for an app... i don't think Shared objects would benefit me for the amount i need to save...
Find more inspiration, events, and resources on the new Adobe Community
Explore Now