GDI+: Introduction to Bitmaps |
|
Practical Learning: Creating a Bitmap |
Using a Bitmap |
To support bitmaps, GDI+ provides the Bitmap class. The Bitmap class is based on the abstract Image class. If you have created a bitmap and stored it as a file, you can pass the path of that file to the following constructor of the class: public: Bitmap(String *filename); Once the picture is ready, to present it to the user, you can call the Graphics::DrawImage() method that is overloaded with as many different versions as you can possibly need. One of the versions of this method has the following syntax: public: void DrawImage(Image *img, Point point); The first argument can be a bitmap that you can have previously initialized. The second argument specifies the location where the picture will be drawn, which will be the top-left corner of the picture with regards to its parent. Here is an example: |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { Bitmap *bmpFood = new Bitmap(S"FoodBasket.bmp"); e->Graphics->DrawImage(bmpFood, 0, 0); } |
Practical Learning: Displaying a Bitmap |
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { Bitmap *butterfly = new Bitmap(S"Butterfly.bmp"); e->Graphics->DrawImage(butterfly, 10, 10); } |
|
||
Home | Copyright © 2004-2010 FunctionX, Inc. | |
|