Exemple #1
0
        public Bitmap GetTextureBitmap()
        {
            if (Texture is Asset)
            {
                Asset asset   = Texture as Asset;
                long  assetId = asset.Id;

                if (!TextureAlloc.ContainsKey(assetId))
                {
                    byte[] buffer = asset.GetContent();

                    TextureAllocation alloc = new TextureAllocation();
                    alloc.Stream  = new MemoryStream(buffer);
                    alloc.Texture = Image.FromStream(alloc.Stream) as Bitmap;

                    TextureAlloc.Add(assetId, alloc);
                }

                return(TextureAlloc[assetId].Texture);
            }
            else if (Texture is Bitmap)
            {
                return(Texture as Bitmap);
            }
            else
            {
                throw new InvalidDataException("The Texture of this CompositData was assigned a garbage value.");
            }
        }
        public static void FreeAllocatedTextures()
        {
            long[] assetIds = TextureAlloc.Keys.ToArray();

            foreach (long assetId in assetIds)
            {
                TextureAllocation alloc = TextureAlloc[assetId];
                TextureAlloc.Remove(assetId);

                alloc.Texture.Dispose();
                alloc.Texture = null;

                alloc.Stream.Dispose();
                alloc.Stream = null;
            }
        }