jhilb Posted April 21, 2003 Posted April 21, 2003 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. Quote
jhilb Posted April 21, 2003 Author Posted April 21, 2003 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. Quote
*Experts* Nerseus Posted April 21, 2003 *Experts* Posted April 21, 2003 (edited) How are you storing your images? As pictureboxes, one picturebox and one file just loaded from disk? Let's 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"); You'll also need a Graphics object that's 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 Edited April 22, 2003 by Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
hog Posted May 5, 2003 Posted May 5, 2003 Is it possible to say open a jpeg file for example and load and display it onto a button? I'm attempting to do this and am not getting anywhere?? I'm 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? Quote My website
hog Posted May 5, 2003 Posted May 5, 2003 Aha just read Divils post on " Resizing jpg images" so I'll see how I get on with that Quote My website
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.