Copying piece of image to another?

jhilb

Active member
Joined
Jan 14, 2002
Messages
27
I am pretty new to GDI. I have a image set up ok.

Now I have another image (on a GIF file on disk) that I want to copy a portion of to my first image. How is this done? ANyone have a link to something similar?

Also looking for any good web pages showing all the different kinds of textual graphics that can be done.
 
anyone?

I am just looking for some code to load an image into memory and copy a portion of that image to another image in memory.
 
How are you storing your images? As pictureboxes, one picturebox and one file just loaded from disk?

Lets assume you have a picturebox with a picture of some kind and you want to load a gif and copy that gif on top of the picture in the PictureBox. The general idea is to load the gif into a Bitmap object and paint it onto the picturebox. You can create a bitmap with (C#):
Bitmap b = new Bitmap(@"c:\temp\bitmap1.bmp");

Youll also need a Graphics object thats associated to your picturebox. The Graphics object handles the drawing:
Graphics g = pictureBox1.CreateGraphics();

Now you can use g.DrawImage(b,...); to handle the drawing. There are 30 overloads for DrawImage, most handle drawing portions of the bitmap to a portion of the picturebox (to handle scaling, cropping, etc.).

If you want to rapidly draw a gif onto a picturebox, for a game for instance, then you will find lots of samples. Search google for DrawImage and Bitmap and C# or whatever your favorite language is.

-Nerseus
 
Last edited by a moderator:
Is it possible to say open a jpeg file for example and load and display it onto a button?

Im attempting to do this and am not getting anywhere??

Im hoping to be able to open a image file and first of all see if I can scale it to fit neatly on the button. I then want to move on to takinging a portion of the image and using that portion to fill the button.

Am I asking too much?
 
Aha just read Divils post on " Resizing jpg images" so Ill see how I get on with that
 
Back
Top