-
Client Software Programmer
base64
hi, i have a script to decode base64 data which is supposed to be a raw png's data in as2
how can i use that decoded png data to create bitmap again.
thanks.
PHP Code:
var _Chars:Array=new Array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/');_CharsReverseLookup=new Array();for(i=0;i<_Chars.length;i++){_CharsReverseLookup[_Chars[i]]=i;}function readBase64(){if(!_base64Str){return_EndOfInput;}if(_base64Count>=_base64Str.length){return _EndOfInput;}var c:Number=_base64Str.charCodeAt(_base64Count)&0xff;_base64Count++;return c;}function base64encode(str){_base64Str=str;_base64Count=0;var result="";var inBuffer=new Array(3);var lineCount=0;var done=false;while(!done &&(inBuffer[0]=readBase64())!=_EndOfInput){inBuffer[1]=readBase64();inBuffer[2]=readBase64();result+=(_Chars[inBuffer[0]>>2]);if(inBuffer[1]!=_EndOfInput){result+=(_Chars[((inBuffer[0]<<4)&0x30)|(inBuffer[1]>>4)]);if(inBuffer[2]!=_EndOfInput){result+=(_Chars[((inBuffer[1]<<2)&0x3c)|(inBuffer[2]>>6)]);
result+=(_Chars[inBuffer[2]&0x3F]);}else{result+=(_Chars[((inBuffer[1]<<2)&0x3c)]);result+=("=");done=true;}}else{result+=(_Chars[((inBuffer[0]<<4)&0x30)]);result+="=";result+="=";done=true;}lineCount+= 4;if(lineCount>=76){result+=('\n');lineCount=0;}}return result;}function readReverseBase64(){if(!_base64Str){return _EndOfInput;}while(true){if(_base64Count>=_base64Str.length){return _EndOfInput;}var nextCharacter:String=_base64Str.charAt(_base64Count);_base64Count++;if(_CharsReverseLookup[nextCharacter]){return _CharsReverseLookup[nextCharacter];}if(nextCharacter =='A'){return 0;}}return _EndOfInput;}function ntos(n){var str:String=n.toString(16);if(str.length ==1)str="0"+str;str="%"+str;return unescape(str);}function base64decode(str){_base64Str=str;_base64Count=0;var result="";var inBuffer:Array=new Array(4);var done=false;while(!done &&(inBuffer[0]=readReverseBase64())!=_EndOfInput&&(inBuffer[1]=readReverseBase64())!=_EndOfInput){inBuffer[2]=readReverseBase64();inBuffer[3]=readReverseBase64();
result+=ntos((((inBuffer[0]<<2)&0xff)|inBuffer[1]>>4));if(inBuffer[2]!=_EndOfInput){result+=ntos((((inBuffer[1]<<4)&0xff)|inBuffer[2]>>2));if(inBuffer[3]!=_EndOfInput){result+= ntos((((inBuffer[2]<<6) & 0xff) | inBuffer[3]));}else{done=true;}}else{done=true;}}return result;}function pad(str, len, pad){var result:String=str;for(i=str.length;i<len;i++){result=pad+result;}return result;}
and this is the function i call which decodes the png its like a little 8bit guy:
PHP Code:
trace(base64decode('iVBORw0KGgoAAAANSUhEUgAAAB8AAAAwCAYAAADpVKHaAAAB2UlEQVRYhe1Xu23DMBB9MryCVLjyDsoi6TKBPEUQBAmQAVLZE2SGFJkg2sGVCmmDNJfCInGieEdSVmQDzgMMWD6K7+7dh3SGRJQbkGavG2Sxe60SSVVitm5e8r+AKlFKFBK0NHgNEXl1109yYK2/JhOGbCGHgIVyLikZHTntq6h12dsnyp+jfa4bWQVv5HUzlPL7KY7Yt16Tf7FWKzcgV/5RFfIFPIJsdxisc9Ng7dstcDyC9hWy3cFGbuTnlW9zPkdPp0KU3ZdnIgKq/uOiopOdrw8UaXTOY6s9Za3V35U9tcIl3D0Pa8Wbc/YjxUynVPhGrDjb6yZNah9Yh3h5LnqkShMu+jZyDkIkBPjl50NHsav7Rx8sI6/OrAfgmq9RDHYGaBE78z+4t092MoeCj6y7fw17eHLE1ouUf5931LYtiqIAALRtq3ovgb/ff1fJSSPL8zyKtOs61RnOaWQnTsqJpM1CcPcw+xdFQcaB65twS8E7ZKZKnbrHCn1rLYWeiwBQBqfYJJxb7Rym8i+f8/zrffBj9vAy6ncTkaSA1t/08ei13W6r2Uuja5g6012wsTriXfMHhrn/vVzfBVI68BeJfOodbpY03W6r/ZPfHrl2sZfaJ3U2iBy/86G9nGexkcsAAAAASUVORK5CYII='));
-
Senior Member
1 stop using that crap (as2)
2 in as3 you have this:
PHP Code:
var loader:Loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.INIT, function(e:Event):void { bmpData.draw(loader); }); loader.loadBytes(byteArray);
-
Client Software Programmer
-
Client Software Programmer
you dont have an as2 version?
-
Senior Member
-
Client Software Programmer
ok so this script loads a textfile that has bitmap data and loads up the image properly.
PHP Code:
var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth()); var image:MovieClip = mc.createEmptyMovieClip("image", mc.getNextHighestDepth()); image.loadMovie("8bit.txt");
how do i replace that scripts file path, with the actual bitmap data
i'll give you $5 paypal for that answer.
-
Senior Member
you could use some echo.php?data=... where the script would just do <?php echo base64_decode($_GET["data"]); ?> but this would be gaping security hole if placed into wrong domain
-
Client Software Programmer
-
Senior Member
-
Client Software Programmer
image.loadBytes('decoded data here');
doesnt seem to be working for me. :/
-
Senior Member
because that's as3 ) it totally works in as3: http://wonderfl.net/c/ufnD
-
.
-
Client Software Programmer
oh hey fruitbeard, i was listening to station 14 the other day on fruitbeard.net. Why do you guys keep posting as3, do either of you have the formula to create a png in as2 using these tools: >> << .setPixel(,,,); and decoded data. im going to try to ri the as3 encoder than. unless you have a solution for as2
-
Senior Member
Why do you guys keep posting as3, do either of you have the formula to create a png in as2...
that's like asking why do you guys keep sending me to the doctor when I specifically ask for homeopathic remedies.
-
Client Software Programmer
Originally Posted by realMakc
that's like asking why do you guys keep sending me to the doctor when I specifically ask for homeopathic remedies.
thats like implying you rather go downhill than uphill
-
Client Software Programmer
If someone helps me out with changing the pixel getters to setters in this and converts it to as2 ill buy adobe flan-imate and move on how about that.
as3:
PHP Code:
package com.adobe.images { import flash.geom.*; import flash.display.Bitmap; import flash.display.BitmapData; import flash.utils.ByteArray; /** * Class that converts BitmapData into a valid PNG */ public class PNGEncoder { /** * Created a PNG image from the specified BitmapData * * @param image The BitmapData that will be converted into the PNG format. * @return a ByteArray representing the PNG encoded image data. * @langversion ActionScript 3.0 * @playerversion Flash 9.0 * @tiptext */ public static function encode(img:BitmapData):ByteArray { // Create output byte array var png:ByteArray = new ByteArray(); // Write PNG signature png.writeUnsignedInt(0x89504e47); png.writeUnsignedInt(0x0D0A1A0A); // Build IHDR chunk var IHDR:ByteArray = new ByteArray(); IHDR.writeInt(img.width); IHDR.writeInt(img.height); IHDR.writeUnsignedInt(0x08060000); // 32bit RGBA IHDR.writeByte(0); writeChunk(png,0x49484452,IHDR); // Build IDAT chunk var IDAT:ByteArray= new ByteArray(); for(var i:int=0;i < img.height;i++) { // no filter IDAT.writeByte(0); var p:uint; var j:int; if ( !img.transparent ) { for(j=0;j < img.width;j++) { p = img.getPixel(j,i); IDAT.writeUnsignedInt( uint(((p&0xFFFFFF) << 8)|0xFF)); } } else { for(j=0;j < img.width;j++) { p = img.getPixel32(j,i); IDAT.writeUnsignedInt( uint(((p&0xFFFFFF) << 8)| (p>>>24))); } } } IDAT.compress(); writeChunk(png,0x49444154,IDAT); // Build IEND chunk writeChunk(png,0x49454E44,null); // return PNG return png; } private static var crcTable:Array; private static var crcTableComputed:Boolean = false; private static function writeChunk(png:ByteArray, type:uint, data:ByteArray):void { if (!crcTableComputed) { crcTableComputed = true; crcTable = []; var c:uint; for (var n:uint = 0; n < 256; n++) { c = n; for (var k:uint = 0; k < 8; k++) { if (c & 1) { c = uint(uint(0xedb88320) ^ uint(c >>> 1)); } else { c = uint(c >>> 1); } } crcTable[n] = c; } } var len:uint = 0; if (data != null) { len = data.length; } png.writeUnsignedInt(len); var p:uint = png.position; png.writeUnsignedInt(type); if ( data != null ) { png.writeBytes(data); } var e:uint = png.position; png.position = p; c = 0xffffffff; for (var i:int = 0; i < (e-p); i++) { c = uint(crcTable[(c ^ png.readUnsignedByte()) & uint(0xff)] ^ uint(c >>> 8)); } c = uint(c^uint(0xffffffff)); png.position = e; png.writeUnsignedInt(c); } } }
look at this poor dessert waiting to be combined and subscribed too: http://i.imgur.com/yujeyyJ.png
Last edited by AS3.0; 05-24-2016 at 05:47 PM.
-
Client Software Programmer
-
Client Software Programmer
this attempt felt promising but it comes out as a black image using the data so idk:
PHP Code:
var _Chars:Array=new Array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/');_CharsReverseLookup=new Array();for(i=0;i<_Chars.length;i++){_CharsReverseLookup[_Chars[i]]=i;}function readBase64(){if(!_base64Str){return_EndOfInput;}if(_base64Count>=_base64Str.length){return _EndOfInput;}var c:Number=_base64Str.charCodeAt(_base64Count)&0xff;_base64Count++;return c;}function base64encode(str){_base64Str=str;_base64Count=0;var result="";var inBuffer=new Array(3);var lineCount=0;var done=false;while(!done &&(inBuffer[0]=readBase64())!=_EndOfInput){inBuffer[1]=readBase64();inBuffer[2]=readBase64();result+=(_Chars[inBuffer[0]>>2]);if(inBuffer[1]!=_EndOfInput){result+=(_Chars[((inBuffer[0]<<4)&0x30)|(inBuffer[1]>>4)]);if(inBuffer[2]!=_EndOfInput){result+=(_Chars[((inBuffer[1]<<2)&0x3c)|(inBuffer[2]>>6)]); result+=(_Chars[inBuffer[2]&0x3F]);}else{result+=(_Chars[((inBuffer[1]<<2)&0x3c)]);result+=("=");done=true;}}else{result+=(_Chars[((inBuffer[0]<<4)&0x30)]);result+="=";result+="=";done=true;}lineCount+= 4;if(lineCount>=76){result+=('\n');lineCount=0;}}return result;}function readReverseBase64(){if(!_base64Str){return _EndOfInput;}while(true){if(_base64Count>=_base64Str.length){return _EndOfInput;}var nextCharacter:String=_base64Str.charAt(_base64Count);_base64Count++;if(_CharsReverseLookup[nextCharacter]){return _CharsReverseLookup[nextCharacter];}if(nextCharacter =='A'){return 0;}}return _EndOfInput;}function ntos(n){var str:String=n.toString(16);if(str.length ==1)str="0"+str;str="%"+str;return unescape(str);}function base64decode(str){_base64Str=str;_base64Count=0;var result="";var inBuffer:Array=new Array(4);var done=false;while(!done &&(inBuffer[0]=readReverseBase64())!=_EndOfInput&&(inBuffer[1]=readReverseBase64())!=_EndOfInput){inBuffer[2]=readReverseBase64();inBuffer[3]=readReverseBase64(); result+=ntos((((inBuffer[0]<<2)&0xff)|inBuffer[1]>>4));if(inBuffer[2]!=_EndOfInput){result+=ntos((((inBuffer[1]<<4)&0xff)|inBuffer[2]>>2));if(inBuffer[3]!=_EndOfInput){result+= ntos((((inBuffer[2]<<6) & 0xff) | inBuffer[3]));}else{done=true;}}else{done=true;}}return result;}function pad(str, len, pad){var result:String=str;for(i=str.length;i<len;i++){result=pad+result;}return result;}
import flash.display.BitmapData; import flash.geom.Rectangle; import flash.geom.Point;
var bitmapData_1:BitmapData = new BitmapData(100, 80, false, base64decode('iVBORw0KGgoAAAANSUhEUgAAAB8AAAAwCAYAAADpVKHaAAAB2UlEQVRYhe1Xu23DMBB9MryCVLjyDsoi6TKBPEUQBAmQAVLZE2SGFJkg2sGVCmmDNJfCInGieEdSVmQDzgMMWD6K7+7dh3SGRJQbkGavG2Sxe60SSVVitm5e8r+AKlFKFBK0NHgNEXl1109yYK2/JhOGbCGHgIVyLikZHTntq6h12dsnyp+jfa4bWQVv5HUzlPL7KY7Yt16Tf7FWKzcgV/5RFfIFPIJsdxisc9Ng7dstcDyC9hWy3cFGbuTnlW9zPkdPp0KU3ZdnIgKq/uOiopOdrw8UaXTOY6s9Za3V35U9tcIl3D0Pa8Wbc/YjxUynVPhGrDjb6yZNah9Yh3h5LnqkShMu+jZyDkIkBPjl50NHsav7Rx8sI6/OrAfgmq9RDHYGaBE78z+4t092MoeCj6y7fw17eHLE1ouUf5931LYtiqIAALRtq3ovgb/ff1fJSSPL8zyKtOs61RnOaWQnTsqJpM1CcPcw+xdFQcaB65twS8E7ZKZKnbrHCn1rLYWeiwBQBqfYJJxb7Rym8i+f8/zrffBj9vAy6ncTkaSA1t/08ei13W6r2Uuja5g6012wsTriXfMHhrn/vVzfBVI68BeJfOodbpY03W6r/ZPfHrl2sZfaJ3U2iBy/86G9nGexkcsAAAAASUVORK5CYII=')); var bitmapData_2:BitmapData = new BitmapData(100, 80, false, 0x00FF0000); var mc_1:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth()); mc_1.attachBitmap(bitmapData_1, this.getNextHighestDepth());
var mc_2:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth()); mc_2.attachBitmap(bitmapData_2, this.getNextHighestDepth()); mc_2._x = 101;
myListener.onRelease = function () { bitmapData_2.copyPixels(bitmapData_1, new Rectangle(0, 0, 100, 80), new Point(0,0)); };
-
.
Hi,
Your above code is just converting new BitmapData(100, 80, false, base64decode(........ to new BitmapData(100, 80, false,0x00000000 as it doesn't know what to make of it, defaults to it.
it isn't loading any image at all.
so you might as well just use:
var bitmapData_1:BitmapData = new BitmapData(100, 80, false, 0x00000000);
var bitmapData_2:BitmapData = new BitmapData(100, 80, false, 0x00FF0000);
http://www.mzan.com/article/4239930-...-jpg-png.shtml
if you read the links given you will see why you are being told to use AS3
http://stackoverflow.com/questions/6...tring-possible
Last edited by fruitbeard; 05-25-2016 at 05:46 AM.
-
.
Hi,
Here is an example in AS3 with your 8bit guy image loading.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|