Start learning the flexlib control!
To convert images to base64, you can use the flexlib: base64image control to convert images to base64, and imagesnapshot to convert images to base64.
The following implementation method is not necessarily the best. If you have a better method, please give us some advice. Thank you!
View code
<? XML version = "1.0" encoding = "UTF-8"?>
<S: Application xmlns: FX = "http://ns.adobe.com/mxml/2009"
Xmlns: S = "Library: // ns.adobe.com/flex/spark"
Xmlns: MX = "Library: // ns.adobe.com/flex/mx" minwidth = "955" minheight = "600"
Xmlns: flexlib = "http://code.google.com/p/flexlib/">
<FX: declarations>
<! -- Place non-visual elements (such as services and value objects) Here -->
</FX: declarations>
<FX: SCRIPT>
<! [CDATA [
Import Flash. utils. bytearray;
Import MX. utils. base64decoder;
Import MX. utils. stringutil;
Import MX. Graphics. imagesnapshot;
[Embed (Source = "assets/images/aaa.gif")]
Public VaR Cat: class;
Protected Function Btnsetpic_clickhandler (Event: mouseevent): void
{
Lib64img2. Source = cat;
}
Protected Function Imgtobase64_clickhandler (Event: mouseevent): void
{
VaR Ohsnap: imagesnapshot = imagesnapshot. captureimage (lib64img2 );
Txta1.text = imagesnapshot. encodeimageasbase64 (ohsnap );
}
Protected Function Base64toimg_clickhandler (Event: mouseevent): void
{
Lib64img. value = txta2.text;
}
]>
</FX: SCRIPT>
<S: hgroup>
<S: button y = "120" label = "set image" id = "btnsetpic" Click = "btnsetpic_clickhandler (event)"/>
<Flexlib: base64image id = "lib64img2" width = "100" Height = "100"/>
<S: button id = "base64toimg" label = "Convert image to base64" Click = "imgtobase64_clickhandler (event)"/>
<S: textarea id = "txta1" width = "200" Height = "100"/>
</S: hgroup>
& Lt; s: hgroup y = "150" & gt;
<S: textarea id = "txta2" width = "200" Height = "100"/>
<S: button id = "imgtobase64" label = "base64 to image conversion" Click = "base64toimg_clickhandler (event)"/>
<Flexlib: base64image id = "lib64img" width = "100" Height = "100"/>
</S: hgroup>
</S: Application>