CreateMaskFromColor() public method

Create a transparency mask from a specified colorkey
public CreateMaskFromColor ( System.Color color ) : void
color System.Color Color to become transparent
return void
示例#1
0
 public static Texture removeMask(Image image)
 {
     image.CreateMaskFromColor(MASK_COLOUR, 0);
     return new Texture(image, new IntRect(0, 0, (int)(image.Size.X), (int)(image.Size.Y)));
 }
示例#2
0
            /// <summary>
            /// Draws the <see cref="Image"/> for this atlas.
            /// </summary>
            /// <param name="padding">The amount to pad each item.</param>
            /// <param name="successfulItems">An IEnumerable of the <see cref="AtlasTextureItem"/>s that were
            /// successfully draw to the atlas.</param>
            /// <returns>A <see cref="Image"/> of the atlas.</returns>
            Image DrawAtlas(int padding, out IEnumerable<AtlasTextureItem> successfulItems)
            {
                // Create the list for successful items
                var successful = new List<AtlasTextureItem>();
                successfulItems = successful;

                // Try to create the atlas texture. If any exceptions are thrown when trying to create the texture,
                // do not use a texture atlas at all.
                const string errmsg = "Failed to create TextureAtlas texture. Exception: {0}";
                Image ret = null;
                try
                {
                    ret = new Image((uint)_width, (uint)_height, _backColor) { Smooth = false };
                    ret.CreateMaskFromColor(_backColor);
                    DrawAtlasDrawingHandler(ret, padding, successful);
                }
                catch (ObjectDisposedException ex)
                {
                    if (log.IsErrorEnabled)
                        log.ErrorFormat(errmsg, ex);
                }
                catch (Exception ex)
                {
                    if (log.IsErrorEnabled)
                        log.ErrorFormat(errmsg, ex);
                    Debug.Fail(string.Format(errmsg, ex));
                }

                // If we have a null Texture2D right here, it means we failed completely to create the atlas.
                // So clear the successful list completely, remove the atlas from all items, and return a null texture.
                if (ret == null)
                {
                    foreach (var node in Nodes)
                    {
                        node.ITextureAtlasable.RemoveAtlas();
                    }

                    successful.Clear();

                    return null;
                }

#pragma warning disable 162
                // Save the generated atlas
                // ReSharper disable ConditionIsAlwaysTrueOrFalse
                if (_saveGeneratedAtlasToTemp)
                    SaveTextureToTempFile(ret);
                // ReSharper restore ConditionIsAlwaysTrueOrFalse
#pragma warning restore 162

                return ret;
            }