示例#1
0
 private void SetTransparentColor(TextureResource resource)
 {
     ClearTransparentColor(resource);
     resource.Apply(c => {
         if (c.Equals(_transColor))
         {
             return(Colors.Transparent);
         }
         else
         {
             return(c);
         }
     });
 }
示例#2
0
        public static TextureResource CreateTextureResource(Bitmap image)
        {
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }

            TextureResource tex = new TextureResource(image.Width, image.Height);

            if (image.PixelFormat != PixelFormat.Format32bppArgb)
            {
                using (Bitmap compatImage = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppArgb)) {
                    compatImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);
                    using (Graphics g = Graphics.FromImage(compatImage)) {
                        g.CompositingMode   = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
                        g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
                        g.DrawImage(image, new Point(0, 0));
                    }

                    Rectangle  rect    = new Rectangle(0, 0, compatImage.Width, compatImage.Height);
                    BitmapData bmpData = compatImage.LockBits(rect, ImageLockMode.ReadOnly, compatImage.PixelFormat);

                    IntPtr ptr = bmpData.Scan0;
                    System.Runtime.InteropServices.Marshal.Copy(ptr, tex.RawData, 0, tex.RawData.Length);

                    compatImage.UnlockBits(bmpData);
                }
            }
            else
            {
                Rectangle  rect    = new Rectangle(0, 0, image.Width, image.Height);
                BitmapData bmpData = image.LockBits(rect, ImageLockMode.ReadOnly, image.PixelFormat);

                IntPtr ptr = bmpData.Scan0;
                System.Runtime.InteropServices.Marshal.Copy(ptr, tex.RawData, 0, tex.RawData.Length);

                image.UnlockBits(bmpData);
            }

            tex.Apply(c => { return(new TFColor(c.B, c.G, c.R, c.A)); });

            return(tex);
        }
示例#3
0
        public override TextureResource Transform(TextureResource data, int width, int height)
        {
            //byte[] tdata = new byte[width * height];

            TextureResource transData = new TextureResource(width, height);

            transData.Apply((c, x, y) =>
            {
                return(data[width - x, y]);
            });

            /*for (int y = 0; y < height; y++) {
             *  for (int x = 0; x < width; x++) {
             *      int dindex = y * width + x;
             *      int tindex = y * width + (width - x);
             *      tdata[tindex] = data[dindex];
             *  }
             * }*/

            return(transData);
        }
示例#4
0
        public static Bitmap CreateBitmap(this TextureResource self)
        {
            if (self == null)
            {
                return(null);
            }

            TextureResource tex = self.Crop(self.Bounds);

            tex.Apply(c => { return(new TFColor(c.B, c.G, c.R, c.A)); });

            Bitmap bmp = new Bitmap(tex.Width, tex.Height, PixelFormat.Format32bppArgb);

            Rectangle  rect    = new Rectangle(0, 0, tex.Width, tex.Height);
            BitmapData bmpData = bmp.LockBits(rect, ImageLockMode.WriteOnly, bmp.PixelFormat);

            IntPtr ptr = bmpData.Scan0;

            Marshal.Copy(tex.RawData, 0, ptr, tex.RawData.Length);

            bmp.UnlockBits(bmpData);

            return(bmp);
        }