コード例 #1
0
ファイル: CPImageToObject.cs プロジェクト: ishani/InSiDe
        void FindObjectExtents()
        {
            lbSubs.Items.Clear();
              ObjectExtents.Clear();

              Int32 objectSpacingX = (Int32)spacingX.Value;
              Int32 objectSpacingY = (Int32)spacingY.Value;

              if (!extractMultiple.Checked)
              {
            objectSpacingX = TargetBitmap.Width;
            objectSpacingY = TargetBitmap.Height;
              }

              BitmapData bmpData = TargetBitmap.LockBits(new Rectangle(0, 0, TargetBitmap.Width, TargetBitmap.Height), ImageLockMode.ReadOnly, TargetBitmap.PixelFormat);
              {
            Int32 curX = 0, curY = 0;
            while (curY < bmpData.Height)
            {
              while (curX < bmpData.Width)
              {
            Rectangle ext = ExtractExtentsFromArea(bmpData, curX, objectSpacingX, curY, objectSpacingY);
            if (ext.Width > 0 && ext.Height > 0)
            {
              ExtractedObject eo = new ExtractedObject(
                findInnerEdges.Checked ? ext : new Rectangle(curX, curY, objectSpacingX, objectSpacingY));

              ObjectExtents.Add(eo);
              lbSubs.Items.Add(eo);
            }

            curX += objectSpacingX;
              }

              curX = 0;
              curY += objectSpacingY;
            }
              }
              TargetBitmap.UnlockBits(bmpData);

              foreach (ExtractedObject eo in ObjectExtents)
              {
            CreateTileSlices(eo);
              }
        }
コード例 #2
0
ファイル: CPImageToObject.cs プロジェクト: ishani/InSiDe
        void CreateTileSlices(ExtractedObject eo)
        {
            eo.slices.Clear();

              // configure for TopLeft y default
              Int32 curX = 0, curY = 0;
              Int32 deltaX = Constants.TileSize, deltaY = Constants.TileSize;
              IterationOp outer = cur => (cur < eo.bounds.Height),
                  inner = cur => (cur < eo.bounds.Width);

              if (edgeBL.Checked || edgeBR.Checked)
              {
            curY = eo.bounds.Height - Constants.TileSize;
            deltaY = -Constants.TileSize;

            outer = cur => (cur > -Constants.TileSize);
              }
              if (edgeTR.Checked || edgeBR.Checked)
              {
            curX = eo.bounds.Width - Constants.TileSize;
            deltaX = -Constants.TileSize;

            inner = cur => (cur > -Constants.TileSize);
              }

              Int32 xReset = curX;
              while (outer(curY))
              {
            while (inner(curX))
            {
              Rectangle sliceRect = new Rectangle(eo.bounds.Left + curX, eo.bounds.Top + curY, Constants.TileSize, Constants.TileSize);
              eo.slices.Add(sliceRect);

              curX += deltaX;
            }

            curX = xReset;
            curY += deltaY;
              }
        }