Exemplo n.º 1
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="strFrameSet"></param>
 /// <param name="strFrame"></param>
 /// <param name="frm"></param>
 /// <returns></returns>
 public bool AddFrame(string strFrameSet, string strFrame, Frame frm)
 {
     FrameSet frms;
     if (Items.Contains(strFrameSet)) {
         frms = (FrameSet)Items[strFrameSet];
     } else {
         frms = new FrameSet(strFrameSet);
         Items.Add(strFrameSet, frms);
     }
     frms.Add(frm);
     return true;
 }
Exemplo n.º 2
0
        public static bool Import(AnimSet anis, string[] astrFileNames)
        {
            // By sorting the filenames we introduce a useful bit of determinism.

            Array.Sort(astrFileNames);

            // Enumerate all the filenames and for each one:

            Color clrTransparent = Color.FromArgb(0xff, 0, 0xff);
            SolidBrush brTransparent = new SolidBrush(clrTransparent);

            foreach (string strFile in astrFileNames) {

                // 1. Read the bitmap from it.

                Bitmap bm;
                try {
                    bm = new Bitmap(strFile);
                } catch {
                    Console.WriteLine("Error: Can't load \"{0}\"", strFile);
                    return false;
                }

                // 2. 'Normalize' the bitmap. Normalized bitmaps are 24-bit, 'tight',
                //    have the proper transparent color, and an origin.

                // All pixels the same color as the upper-left pixel get mapped to the
                // transparent color

                bm.MakeTransparent(bm.GetPixel(0, 0));

                Bitmap bmT = new Bitmap(bm.Width, bm.Height, PixelFormat.Format24bppRgb);
                using (Graphics g = Graphics.FromImage(bmT)) {

                    // Prep the new image by filling with the transparent color

                    g.FillRectangle(brTransparent, 0, 0, bm.Width, bm.Height);

                    // Convert the Bitmap to 24-bpp while leaving transparent pixels behind

                    g.DrawImageUnscaled(bm, 0, 0);
                }

                bm = bmT;

                // UNDONE: any color mapping

                // Find the tight boundary of the image and create a new Bitmap with just
                // that portion of the Bitmap
                // OPT: this could be made faster by doing four independent edge scans

                int xL = bm.Width;
                int xR = 0;
                int yT = bm.Height;
                int yB = 0;
                for (int y = 0; y < bm.Height; y++) {
                    for (int x = 0; x < bm.Width; x++) {
                        Color clr = bm.GetPixel(x, y);
                        if (clr != clrTransparent) {
                            xL = Math.Min(xL, x);
                            xR = Math.Max(xR, x);
                            yT = Math.Min(yT, y);
                            yB = Math.Max(yB, y);
                        }
                    }
                }
                int cx = xR - xL + 1;
                int cy = yB - yT + 1;
                int xOrigin = bm.Width / 2 - xL;
                int yOrigin = bm.Height / 2 - yT;

                bmT = new Bitmap(cx, cy, PixelFormat.Format24bppRgb);
                using (Graphics g = Graphics.FromImage(bmT)) {
                    Rectangle rcT = new Rectangle(xL, yT, cx, cy);
                    g.DrawImage(bm, 0, 0, rcT, GraphicsUnit.Pixel);
                }

                bm = bmT;

                // 3. Create a Frame object which references the normalized bitmap.

                Frame frm = new Frame(bm, xOrigin, yOrigin);

                // 4. Assign it to the proper Anim and FrameSet by using info parsed
                //    from the bitmap's original filename. If the proper Anim/FrameSet
                //    does not yet exist, create it.

                string[] astr = strFile.Substring(strFile.LastIndexOf('\\') + 1).Split('_', '.');
                if (astr.Length != 5) {
                    Console.WriteLine("Warning: file {0} does not match the requisite naming pattern", strFile);
                    continue;
                }
                string strAnimSet = astr[0];
                string strAnim = astr[1];
                string strFrameSet = astr[2];
                string strFrame = astr[3];

                anis.Name = strAnimSet;
                anis.AddFrame(strAnim, strFrameSet, strFrame, frm);
            }

            return true;
        }
Exemplo n.º 3
0
 // UNDONE: BUGBUG: This shouldn't be necessary. FrameSet inherits
 // from CollectionBase which implements IList so IList's methods
 // (e.g., Add, IndexOf) should automatically be exposed by FrameSet.
 /// <summary>
 /// 
 /// </summary>
 /// <param name="frm"></param>
 /// <returns></returns>
 public int Add(Frame frm)
 {
     return ((IList)this).Add(frm);
 }
Exemplo n.º 4
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="frm"></param>
 /// <returns></returns>
 public int IndexOf(Frame frm)
 {
     return ((IList)this).IndexOf(frm);
 }
Exemplo n.º 5
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="strAnim"></param>
 /// <param name="strFrameSet"></param>
 /// <param name="strFrame"></param>
 /// <param name="frm"></param>
 /// <returns></returns>
 public bool AddFrame(string strAnim, string strFrameSet, string strFrame, Frame frm)
 {
     Anim ani;
     if (Items.Contains(strAnim)) {
         ani = (Anim)Items[strAnim];
     } else {
         ani = new Anim(strAnim);
         Items.Add(strAnim, ani);
     }
     ani.AddFrame(strFrameSet, strFrame, frm);
     return true;
 }