Highlighted

Air sdk (23, 24) CameraRoll read bytes from image. Problem size.

New Here ,
Jan 27, 2017

Copy link to clipboard

Copied

I've got problem with readBytes image from cameraRoll (ios device, android didn't check). The size of the image is too big. The same image in air sdk 23, sdk 24 has 16MB but in air sdk 22 is 1,8MB (this is correct).

private function connectCamera():void

  {

  if( CameraRoll.supportsBrowseForImage )

  {

  _cameraRoll.addEventListener( MediaEvent.SELECT, imageSelected );

  _cameraRoll.browseForImage();

  }

  else

  {

  trace( "Image browsing is not supported on this device.");

  }

  }

protected function imageSelected(event:MediaEvent):void

  {

  var imagePromise:MediaPromise = event.data;

  dataSource = imagePromise.open();

  if( imagePromise.isAsync )

  {

  trace( "Asynchronous media promise." );

  var eventSource:IEventDispatcher = dataSource as IEventDispatcher;           

  eventSource.addEventListener( Event.COMPLETE, onMediaLoaded );        

  }

  else

  {

  trace( "Synchronous media promise." );

  readMediaData();

  }

  }

private function onMediaLoaded( event:Event 😞void

  {

  trace("Media load complete");

  readMediaData();

  }

  private function readMediaData():void

  {

  var imageBytes:ByteArray = new ByteArray();

  dataSource.readBytes( imageBytes );

  tempDir = File.createTempDirectory();

  var now:Date = new Date();

  var filename:String = "IMG" + now.fullYear + now.month + now.day + now.hours + now.minutes + now.seconds + ".jpg";

  var temp:File = tempDir.resolvePath( filename );

  var stream:FileStream = new FileStream();

  stream.open( temp, FileMode.WRITE );

  stream.writeBytes( imageBytes );

  stream.close();

  trace(imageBytes.length, imageBytes.bytesAvailable);

  }

TOPICS
Performance issues

Views

222

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Air sdk (23, 24) CameraRoll read bytes from image. Problem size.

New Here ,
Jan 27, 2017

Copy link to clipboard

Copied

I've got problem with readBytes image from cameraRoll (ios device, android didn't check). The size of the image is too big. The same image in air sdk 23, sdk 24 has 16MB but in air sdk 22 is 1,8MB (this is correct).

private function connectCamera():void

  {

  if( CameraRoll.supportsBrowseForImage )

  {

  _cameraRoll.addEventListener( MediaEvent.SELECT, imageSelected );

  _cameraRoll.browseForImage();

  }

  else

  {

  trace( "Image browsing is not supported on this device.");

  }

  }

protected function imageSelected(event:MediaEvent):void

  {

  var imagePromise:MediaPromise = event.data;

  dataSource = imagePromise.open();

  if( imagePromise.isAsync )

  {

  trace( "Asynchronous media promise." );

  var eventSource:IEventDispatcher = dataSource as IEventDispatcher;           

  eventSource.addEventListener( Event.COMPLETE, onMediaLoaded );        

  }

  else

  {

  trace( "Synchronous media promise." );

  readMediaData();

  }

  }

private function onMediaLoaded( event:Event 😞void

  {

  trace("Media load complete");

  readMediaData();

  }

  private function readMediaData():void

  {

  var imageBytes:ByteArray = new ByteArray();

  dataSource.readBytes( imageBytes );

  tempDir = File.createTempDirectory();

  var now:Date = new Date();

  var filename:String = "IMG" + now.fullYear + now.month + now.day + now.hours + now.minutes + now.seconds + ".jpg";

  var temp:File = tempDir.resolvePath( filename );

  var stream:FileStream = new FileStream();

  stream.open( temp, FileMode.WRITE );

  stream.writeBytes( imageBytes );

  stream.close();

  trace(imageBytes.length, imageBytes.bytesAvailable);

  }

TOPICS
Performance issues

Views

223

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jan 27, 2017 0

Have something to add?

Join the conversation