Solved

How do you display 16 bit bitmaps?

Posted on 1997-08-30
1
287 Views
Last Modified: 2008-03-06
How is the procedure for displaying 16 bit bitmaps different from 8 bit.  I am using MSVC++ 5.0 and DirectX 5.0.  Are there any good documents on it?  Is it possible to use sprite animation with transparencies in high color?  Thanks a lot.
0
Comment
Question by:brsmith
1 Comment
 

Accepted Solution

by:
jag earned 40 total points
ID: 1168453
That depends on your procedure. If you are loading a 16bit bmp file, you can still use LoadImage and create a memory device context and select the bitmap into it, and then use BitBlt to copy ii to another device context such as one gotten from a direct draw surface or a window.

eg.

HBITMAP hBitmap = LoadImage (NULL, "name", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
if (hBitmap)
{
    // Once you have a valid window handle
    HDC hdc = GetDC (hwnd);

    or

    // Once you have a valid surface
    LPDIRECTDRAWSURFACE lpDDS->GetDC ();


    // Create a memory device context for bitmap
    HDC hMemDC = CreateCompatibleDC (hdc);
    // Select bitmap into device context
    SelectObject (hMemDC, hBitmap);
    // Blit image to other device context
    BitBlt (hdc, x, y, width, height, hMemDC, sourceX, sourceY);

    ReleaseDC (hwnd, hdc);

    or

    lpDDS->ReleaseDC (hdc);

    // Destroy the bitmap
    DeleteObject (hBitmap);

    // Delete the device context
    DeleteDC (hMemDC);
}


This is the crappy way of doing this, but it is quick to implement. If you are going to do animation and sprites, then you will want to go the DirectX route. This means you will probably need to load the image yourself to get access to the pixel data.

You can use LoadImage to do this by specifying LR_CREATEDIBSECTION in the flags, and then using GetObject to get the pixel pointer to the dib section, but this is unreliable.

The biggest problem with 16 bit is that the data format is not standard. You get various formats for rgb packed data, like 5:5:5 bits per gun, or 5:6:5 etc. You will need to find this info out at run-time and convert you loaded image accordingly before you copy it to the display.

DirectX has methods for determining the format, as does Windows GDI. (take a look at the DirectX docs.)

As for the transparency issue, yes you can do this. The DirectDrawSurface blit function takes a blitfx parameter which can be a color key mask. This allows you to specify an rgb color that will not be copied by the blit operation. Most cards will do this in hardware providing your source and destination surfaces are both in video memory.

Hope this helps

Cheers
Justin


0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question