Created
October 17, 2011 06:34
-
-
Save itoz/1292062 to your computer and use it in GitHub Desktop.
DisplayObjectをBase64文字列(png)に変換
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ====================================================================== | |
/** | |
* DisplayObjectをBase64文字列(png)に変換. | |
* @param target 画像化したいDisplayObject | |
* @param w 幅 | |
* @param h 高さ | |
*/ | |
//import com.adobe.images.PNGEncoder; | |
//import mx.utils.Base64Encoder; | |
private function convertBase64(target : DisplayObject, w : Number = NaN, h : Number = NaN) : String | |
{ | |
w = (isNaN(w)) ? target.width : w; | |
h = (isNaN(h)) ? target.height : h; | |
var bmd : BitmapData = new BitmapData(w, h, true, 0x00ffffff); | |
bmd.draw(target); | |
var base64 : Base64Encoder = new Base64Encoder(); | |
base64.encodeBytes(PNGEncoder.encode(bmd)); | |
var str : String = base64.toString(); | |
bmd.dispose(); | |
var str3:String = ""; | |
var str2:String = str.toString(); | |
var len:uint = str2.length; | |
for (var i:uint = 0; i < len; i++) | |
{ | |
var sub:String = str2.substr(i, 1); | |
if (sub == "\n") | |
continue; | |
str3 += sub; | |
} | |
return str3; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment