简体   繁体   English

在as3 Starling中放置纹理

[英]Dispose a texture in as3 Starling

I am currently working on an application where a screenshot of the stage is generated as bitmap image and the generated image is then added to a tab in the application. 我目前正在开发一个应用程序,其中将舞台的屏幕截图生成为位图图像,然后将生成的图像添加到应用程序中的选项卡上。

I am unable to add more than a few screenshot images to the tab. 我无法在选项卡中添加多个屏幕截图图像。 The application throws "Error #3691: Resource limit for this resource type exceeded" exception. 应用程序引发“错误#3691:超出了此资源类型的资源限制”异常。

I found that this exception is thrown because of the texture not being disposed properly. 我发现由于纹理处理不当而引发此异常。 In the code below, If I dispose the bufferedTexture, the image added to the tab is empty. 在下面的代码中,如果我放置bufferedTexture,则添加到选项卡的图像为空。

Below is the code: 下面是代码:

public function AddtoMediaTab():void
{
   var buffer:BitmapData;
   buffer = GetStageAsBitmapData();
   var bufferedTexture:Texture = Texture.fromBitmapData(buffer);
   this.image.source = bufferedTexture;
   buffer.dispose();
   buffer = null;
  //bufferedTexture.dispose(); 
  //bufferedTexture = null;
}

public function GetAsBitmapData():BitmapData
{
    var buffer:BitmapData = new BitmapData(this.width,this.height, false, 0x000000);
    this.media.DrawToBitmap(buffer);
    return buffer;
}

Any help is appreciated. 任何帮助表示赞赏。

Thanks 谢谢

You could try changing the rendering profile. 您可以尝试更改渲染配置文件。 Straight from the Starling API documentation: 直接来自Starling API文档:

starling.core.Starling API starling.core.Starling API

Context3D Profiles Context3D配置文件

Stage3D supports different rendering profiles, and Starling works with all of them. Stage3D支持不同的渲染配置文件,Starling可以使用所有这些渲染配置文件。 The last parameter of the Starling constructor allows you to choose which profile you want. Starling构造函数的最后一个参数允许您选择所需的概要文件。 The following profiles are available: 提供以下配置文件:

  • BASELINE_CONSTRAINED: provides the broadest hardware reach. BASELINE_CONSTRAINED:提供最广泛的硬件支持。 If you develop for the browser, this is the profile you should test with. 如果您是为浏览器开发的,则应使用该配置文件进行测试。
  • BASELINE: recommend for any mobile application, as it allows Starling to use a more memory efficient texture type (RectangleTextures). BASELINE:建议用于任何移动应用程序,因为它允许Starling使用内存效率更高的纹理类型(RectangleTextures)。 It also supports more complex AGAL code. 它还支持更复杂的AGAL代码。
  • BASELINE_EXTENDED: adds support for textures up to 4096x4096 pixels. BASELINE_EXTENDED:添加了对高达4096x4096像素的纹理的支持。 This is especially useful on mobile devices with very high resolutions. 这在分辨率很高的移动设备上特别有用。

The recommendation is to deploy your app with the profile "auto" (which makes Starling pick the best available of those three), but test it in all available profiles. 建议使用“自动”配置文件来部署您的应用程序(这使Starling选择了这三个应用程序中最好的),但要在所有可用的配置文件中对其进行测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM