Windows Programming: Bitmap display

Source: Internet
Author: User
Tags image line

In WIN32, the steps to display a bitmap on a window have some complicated

Instead of drawing the image line directly on the window, it is displayed on the window by a memory handle call

To display a bitmap on a form, first move the bitmap into the resource view



load Bitmap resource: Load bitmap in Resource View

static Hbitmap hbitmap;  Bitmap handle
static BITMAP BITMAP;    Bitmap structure Body


The bitmap structure body is defined as follows:

typedef struct TAGBITMAP
  {
    LONG        bmtype;  Bitmap type
    long        bmwidth;//bitmap
    width        long bmheight;  Bitmap height
    LONG        bmwidthbytes;  Width of the byte
    WORD        bmplanes;
    WORD        bmbitspixel;//Pixel
    lpvoid      bmbits
  } BITMAP, *pbitmap, NEAR *npbitmap, FAR *lpbitmap;

Load bitmap: Loading when the window is created

Case Wm_create:
	{
		hbitmap = LoadBitmap (hinst, Makeintresource (idb_future));  Get bitmap handle
		GetObject (hbitmap, sizeof (BITMAP), &bitmap);  Pass the bitmap handle to the bitmap structure
		
		//Get the width and height of the bitmap
		cxbitmap = bitmap.bmwidth;
		Cybitmap = bitmap.bmheight;

	} Break


To create a Memory environment device:

bitmaps, like windows, specifically require a handle that holds bitmaps, called Bitmap memory dc

HDC Hdcmem;   Bitmap Memory DC

Select a bitmap into a memory DC for drawing on a form

SelectObject (Hdcmem, hbitmap);    To select a bitmap into a memory DC

drawing using the BitBlt () function

Copy the bitmap in the memory DC to the window DC display
BITBLT (hdc, MB, Cxbitmap, Cybitmap, hdcmem,0,0,srccopy);  Execute in a copy way

Parameter description: HDC is a window handle

200,200 indicates the starting coordinates of the drawn window (that is, from where the window is drawn)

Cxbitmap and Cybitmap are the size of the bitmap,

0,0 represents a coordinate on a bitmap on which the program will start drawing

Srccopy represents performing operations in a copy way


Effect:








Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.