Flex gets PNG transparent screenshot of the problem and solution _flex

Source: Internet
Author: User
The code is probably like this:
Copy Code code as follows:

Displaobject for need screenshot object
var pngencoder:pngencoder = new Pngencoder ();
var bitmapdata:bitmpadata = new Bitmpadata (displaobject.widht,displaobject.height);
Bitmapdata.draw (Displaobject);
var Imagebytearray:bytearray = Pngencoder.encode (BitMapData);
.....
Send the Imagebytearray to server side scripts .....

However, the results are not transparent and suspect that the Encode method does not contain an alpha channel. Change to the second method:
Copy Code code as follows:

var Bytes:bytearray = bitmapdata.getpixels (new Rectangle (0,0,bitmapdata.width,bitmapdata.height));
var Imagebytearray2:bytearray = Pngencoder.encodebytearray (bytes,bitmapdata.width,bitmapdata.height,true);

The result still has no transparency information!
So I read each of the manuals carefully and found the following passage:
Transparent:boolean (default = True)-refers to whether the anchored image supports different transparency for each pixel. The default value is true (transparent). To create a fully transparent bitmap, set the value of the transparent parameter to TRUE and set the value of the FillColor parameter to 0x00000000 (or set to 0). Setting the transparent property to false can slightly increase rendering performance.
In other words, transparent = True is not yet, FillColor must also be set to 0x000000!!
Copy Code code as follows:

var bitmapdata:bitmpadata = new Bitmpadata (displaobject.widht,displaobject.height,true,0x000000);

In fact, this setting is quite unreasonable, but later encounter problems or more to look at the manual!

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.