Flex learning notes flexlib controls-_ base64image (image base64 Interchange

Source: Internet
Author: User

 

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>

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.