Skip to main content
Known Participant
July 1, 2009
Question

byte Arrya to bitmap

  • July 1, 2009
  • 1 reply
  • 553 views

i m trying to make a drawing application. in this i have to save my drawing to server and after some time i can reload it in flash in editable format.

i am using jpgenoder for encoding than convert that bytearry to base64 encodede string than i send it to server .

but when i reload that bytearray in flash it uneditable So plz can u tell me how to reload that bytearry in editable form

in am using this code


  public function sendToServer():String {
   var canvasBmp:BitmapData=new BitmapData(_canvasWidth,_canvasHeight,false,0xFFFFFFFF);
   canvasBmp.draw(container);
  var jpgEncoder:JPGEncoder=new JPGEncoder(80);
   var jpgStream:ByteArray=jpgEncoder.encode(canvasBmp);

   var byteArrayAsString:String=Base64.encodeByteArray(jpgStream);

   return byteArrayAsString;

  }

  public function drawingCanvas(xml) {
   xmlLoader = new URLLoader();
   xmlData= new XML();
   xmlLoader.addEventListener(Event.COMPLETE, onComplete);
   xmlLoader.load(new URLRequest("test1.xml"));
  }

  public function onComplete(event:Event) {

   testtxt2.text=event.target.data;
   _xmlResponse=new XML(event.target.data);
   readXMLData(_xmlResponse);

  }

  public function readXMLData(xml) {
   id=xml.@ID;
   status=xml.@Status;
   Owner=xml.@Owner;
   canvasData=xml.@canvas;
   for (var i=0; i<3; i++) {
    _layerId=xml.Layers.Layer.@id;
    _OccupiedBy=xml.Layers.Layer.@OccupiedBy;
    _HashValue=xml.Layers.Layer.@HashValue;
    _layerContent=xml.Layers.Layer;
   

   }
  
  
   var decodeStr:String=_layerContent[0].toString();
   var byteArr:ByteArray=Base64.decodeToByteArray(decodeStr);
   loader = new Loader();
   loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);
   loader.loadBytes(byteArr);


  }

  public function onImageLoaded(e:Event):void {

   container.addChild(loader);
   testtxt2.text+="\n loader.height"+loader.height;

   trace(loader.width + " : " + loader.height);

  }

This topic has been closed for replies.

1 reply

July 1, 2009

Hi Bindu,

I guess once loaded the Image will not be editable directly, but you can draw more over this image.

Do you want to save your Image so that you can reselect the objects like Rectangle/circle and so on???

Is that your problem? If it is then don't save the drawing as an JPG instead save the XML with the list of all shapes and their sizes and positions

and redraw them within flash when an image request is encountered. That will be more helpful

Known Participant
July 1, 2009

how to implement this

July 1, 2009

Tell me your requirements I will give you an Idea.

What all shapes are you  using are you using any images as objects etc...