Skip to main content
Known Participant
March 13, 2015
Answered

error 2030 end of file was encountered: setpixels

  • March 13, 2015
  • 1 reply
  • 1222 views

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);

This topic has been closed for replies.
Correct answer kglad

Trying to convert a MC (newText) into a bitmap then to bytearray and back


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);

1 reply

kglad
Community Expert
March 13, 2015

your target bitmap and rectangle are 'larger' than the bytearray.

fi500005Author
Known Participant
March 13, 2015

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

fi500005Author
Known Participant
March 13, 2015

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);


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...