| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- package com.imt.intimamedia.helpers
- {
- import com.hurlant.util.Base64;
-
- import flash.display.BitmapData;
- import flash.geom.Rectangle;
- import flash.utils.ByteArray;
-
- import mx.utils.Base64Decoder;
- import mx.utils.Base64Encoder;
-
- public class Base64Helper
- {
- public function Base64Helper()
- {
- }
-
- public static function convertToBase64( value : BitmapData ) : String
- {
- if( !value )
- return null;
- var byteArray : ByteArray = value.getPixels(new Rectangle( 0, 0, value.width, value.height ));
-
- var encoder : Base64Encoder = new Base64Encoder();
-
- encoder.encodeBytes( byteArray, 0, byteArray.length );
- var base64data : String = encoder.flush();
- return base64data;
- }
-
- public static function convertFromBase64( value : String, width : int, height : int ) : BitmapData
- {
- if( !value )
- return null;
- var decoder : Base64Decoder = new Base64Decoder;
- decoder.decode( value );
-
- var byteArray : ByteArray = decoder.toByteArray();
- byteArray.position = 0;
-
- var bitmapData : BitmapData = new BitmapData( width, height, true );
- bitmapData.setPixels(new Rectangle( 0, 0, width, height ), byteArray );
-
- return bitmapData;
- }
- }
- }
|