Solved

How do you display 16 bit bitmaps?

Posted on 1997-08-30
1
268 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

746 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now