1

i'm pretty sure, this is a realy simple question. but i can't find something on google so maybe my keywords are just wrong.

Let's say i have a image, we call it "tree". And also a bitmap called "forest", what i now want to do is something like this:

forest.addImage(tree, positionXonBitmap, positionYonBitmap, startPositionXImage, startPositionYImage, ImageLength, ImageWidth);

So Copy the "tree" Image to the "forest" bitmap, in which size and on which position i want.

I can't see any function for bitmaps to doing this. Maybe you know something?

My current approach would be to read out the pixels from the image "tree" and use them in "forest" with setPixel (X, Y). But i think this is a realy bad practice.

I didn't have to use Images or Bitmaps. I'm completly free here. All i want to do is to load an Image from disk and copy it to another Image which i can manipulate and is bigger.

So may you have another idea?!

Thank you

TheRealLife
  • 375
  • 4
  • 20
  • [Sprites](https://stackoverflow.com/q/16112622/1997232) ? – Sinatr May 22 '18 at 08:59
  • Something like this: https://stackoverflow.com/a/11262814/2085504 ? – deramko May 22 '18 at 09:02
  • 3
    https://stackoverflow.com/questions/48524294/create-new-image-from-2-diferent-images-c-sharp/48526762#48526762 You should use `DrawImage` overload, where you can specify your image dimensions. – Paviel Kraskoŭski May 22 '18 at 09:03
  • @PaviełKraskoŭski this is perfect. Thank you a lot. – TheRealLife May 22 '18 at 09:07
  • @Sinatr Thank's for you answer never heart about "Sprites" before so learned something new :) But i think the last answer is the better solution for me. – TheRealLife May 22 '18 at 09:07
  • Another [example](https://stackoverflow.com/questions/29576806/get-bitmap-and-draw-it-into-image/29578268?s=4|53.0081#29578268) – TaW May 22 '18 at 09:30

1 Answers1

0

Create Graphics from Forest image and use DrawImage method as follow:

Bitmap forest = new Bitmap("forest.jpg");
Bitmap tree = new Bitmap("tree.jpg");
Graphics gforest = Graphics.FromImage(forest);
gforest.DrawImage(tree, positionXonBitmap, positionYonBitmap, 
    new Rectangle(startPositionXImage, startPositionYImage, imageLength, imageWidth),
    GraphicsUnit.Pixel);
Hossein Golshani
  • 1,847
  • 5
  • 16
  • 27