Copy() public method

Copy pixels from another image onto this one. This function does a slow pixel copy and should only be used at initialization time
public Copy ( Image source, uint destX, uint destY ) : void
source Image Source image to copy
destX uint X coordinate of the destination position
destY uint Y coordinate of the destination position
return void
Example #1
0
        private void btnSplit_Click(object sender, EventArgs e)
        {
            if (Resource != null)
            {
                btnSplit.Visible = false;

                if (!Directory.Exists(txtOutputPath.Text))
                {
                    Directory.CreateDirectory(txtOutputPath.Text);
                }

                var srcExt = txtFile.Text.Substring(
                    txtFile.Text.LastIndexOf(".") + 1);
                var srcName = txtFile.Text.Substring(
                    txtFile.Text.LastIndexOf(Path.DirectorySeparatorChar) + 1).Replace("." + srcExt, string.Empty);

                var cols   = ((int)numericX.Value >= 1) ? (int)numericX.Value : 1;
                var rows   = ((int)numericY.Value >= 1) ? (int)numericY.Value : 1;
                var width  = (int)Resource.Image.Size.X / cols;
                var height = (int)Resource.Image.Size.Y / rows;

                for (int r = 0; r < rows; r++)
                {
                    for (int c = 0; c < cols; c++)
                    {
                        var destName = txtOutputFormat.Text.Replace(
                            "%f", srcName).Replace(
                            "%ext", srcExt).Replace(
                            "%r", r.ToString()).Replace(
                            "%c", c.ToString()).Replace(
                            "%t", ((r * cols) + c).ToString());

                        Image image = new Image((uint)width, (uint)height);
                        image.Copy(Resource.Image, 0, 0, new IntRect(c * width, r * height, width, height));

                        image.SaveToFile(txtOutputPath.Text + destName);
                        image?.Dispose();
                        image = null;

                        Application.DoEvents();
                    }
                }

                btnSplit.Visible = true;
            }

            txtFile.Focus();
        }
Example #2
0
 /// <summary>
 /// Draws a single item the atlas through a <see cref="ISpriteBatch"/>.
 /// </summary>
 /// <param name="destImg">The <see cref="Image"/> to copy to.</param>
 /// <param name="srcImg">The source <see cref="Image"/>.</param>
 /// <param name="dest">The drawing destination on the atlas.</param>
 /// <param name="src">The source rectangle to draw from the <paramref name="srcImg"/>.</param>
 static void DrawToAtlas(Image destImg, Image srcImg, Vector2 dest, Rectangle src)
 {
     destImg.Copy(srcImg, (uint)dest.X, (uint)dest.Y, (IntRect)src);
 }
Example #3
0
 public Image GetImageAt(uint index)
 {
     Image image = new Image((uint)Sources[index].Width, (uint)Sources[index].Height);
     image.Copy(_canvas, 0, 0, Sources[index]);
     return image;
 }
Example #4
0
 static SurfaceInstance GrabSurface(int x, int y, int w, int h)
 {
     Batch.Flush();
     x *= (Scaled ? 2 : 1);
     y *= (Scaled ? 2 : 1);
     w *= (Scaled ? 2 : 1);
     h *= (Scaled ? 2 : 1);
     using (Image window = _window.Capture())
     {
         Image section = new Image((uint)w, (uint)h);
         section.Copy(window, 0, 0, new IntRect(x, y, w, h));
         return new SurfaceInstance(_engine, section.Pixels, w, h);
     }
 }