Base64」タグアーカイブ

Base64形式のJPEGファイルを表示する

Base64形式でエンコードしたJPEGファイルの文字列をas3でデコードする方法

JPEGのデコードは、AS3 JPEG Decoder – ByteArray.orgを利用

package
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.utils.ByteArray;
    
    import mx.utils.Base64Decoder;
    
    import org.bytearray.decoder.JPEGDecoder;
    
    [SWF(width="1024", height="768", frameRate="60", backgroundColor="#f5f2f0")]
    public class TestBase64 extends Sprite
    {
        private static const base64Data:String = "/9j/4AAQSkZJRgABAgEASABIAAD/4R7sRXhpZgAATU0AKgAAAAgADgEAAAMAAAABAgAAAAEBAAMAAAABAgAAAAECAAMAAAADAAAAtgEDAAMAAAABAAEAAAEGAAMAAAABAAIAAAESAAMAAAABAAEAAAEVAAMAAAABAAMAAAEaAAUAAAABAAAAvAEbAAUAAAABAAAAxAEcAAMAAAABAAEAAAEoAAMAAAABAAIAAAExAAIAAAAeAAAAzAEyAAIAAAAUAAAA6odpAAQAAAABAAABAAAAASwACAAIAAgACvyAAAAnEAAK"; //本当はもっと長く続く
        
        
        public function TestBase64()
        {
            var decoder:Base64Decoder = new Base64Decoder();
            decoder.decode( base64Data );
            var ba:ByteArray = decoder.toByteArray();
                
            
            var myDecoder:JPEGDecoder = new JPEGDecoder();
            myDecoder.parse(ba);
            var width:uint = myDecoder.width;
            var height:uint = myDecoder.height;
            var colorComponents:uint = myDecoder.colorComponents;
            var numComponents:uint = myDecoder.numComponents;
            var pixels:Vector.<uint> = myDecoder.pixels;
            
            var bitmapData:BitmapData = new BitmapData ( width, height, false );
            bitmapData.setVector ( bitmapData.rect, pixels );
            var bmp:Bitmap = new Bitmap( bitmapData );
            addChild( bmp );               
        }
    }
}
Please follow and like us: