导入具有透明背景的 PNG 后,它会显示为白色背景
正如标题已经指出的那样,我在 Flex 4 应用程序中导入 PNG 时遇到了一个(大)问题。
在 Photoshop 中创建一个具有透明背景的 PNG 文件。 使用以下代码在 Flex 应用程序中加载:
thumbnailRef.load();
thumbnailRef 是基于以下方式定义的标签:
<net:FileReference id="thumbnailRef"
select="onBrowseThumbnailRef_select(event);"
complete="onBrowseThumbnailRef_complete(event);" />
因此,当完整事件触发时,数据已加载,并且可以将加载的数据分配给名为 Thumbnail 的图像组件:
private function onBrowseThumbnailRef_complete(evt:Event):void {
Thumbnail.source = thumbnailRef.data;
}
Unitls 现在一切都按预期工作! 但是,当我尝试将缩略图组件的数据发送到 WCF 服务时,我收到一张白色背景的照片:
var thumbBitmapData :BitmapData =
ImageSnapshot.captureBitmapData(Thumbnail.content);
//this is send to the WCF service
ThumbnailByteArray = new PNGEncoder().encode(thumbBitmapData );
我做错了什么吗?
As the title already states i have a (big) problem importing a PNG in a Flex 4 application.
Created a PNG file in Photoshop with transparent background.
Loaded in Flex application using this code:
thumbnailRef.load();
thumbnailRef is defined tag based this way:
<net:FileReference id="thumbnailRef"
select="onBrowseThumbnailRef_select(event);"
complete="onBrowseThumbnailRef_complete(event);" />
So when the complete event fires the data has been loaded and it is possible to assign the data loaded to the image component named Thumbnail:
private function onBrowseThumbnailRef_complete(evt:Event):void {
Thumbnail.source = thumbnailRef.data;
}
Unitls now everything works as expected!
But when i try to send the Thumbnail component's data to a WCF service i receive a photo with white background:
var thumbBitmapData :BitmapData =
ImageSnapshot.captureBitmapData(Thumbnail.content);
//this is send to the WCF service
ThumbnailByteArray = new PNGEncoder().encode(thumbBitmapData );
Am i doing something wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您使用 captureBitmapData 时,它将捕获组件,而不仅仅是位图。我认为您的缩略图组件有白色背景。如果您想上传图片,可以尝试文件参考上传。
When you use captureBitmapData, it will capture the component but not just the bitmap. I think you have a white background for the thumbnail component. If you want to upload the image, you may try the filereference upload.
@杰森:
老实说,我确实玩过thumbnailRef.data。为了控制正在发生的事情,我将 Flex 应用程序转换为 AIR(桌面)应用程序并附加以下内容:
在桌面上打开 test.png 文件再次显示白色背景!据我了解,我所做的是:获取加载的原始数据(驻留在thumbnailRef.data中)并将该数据再次保存到文件系统。
如果正确解释这一点,这意味着“错误”是通过加载数据产生的,但我不知道如何拦截加载或自己控制它(或者我应该自己加载数据......如果是的话如何? )。
奇怪的事情......
@Jason:
To be honest, i did play around with thumbnailRef.data. To have control over what is happening i converted the Flex application to an AIR (desktop) application and appended this:
Opening the test.png file on the desktop shows AGAIN a white background! As i understand what i have done is: taking the raw data loaded (which resides in thumbnailRef.data) and saving this data again to the filesystem.
If interpret this correctly this means that the "error" is produced by loading the data, but i don't have any clue how to intercept the loading or controlling it myself (or should i load the data myself...if yes how?).
Weird things....