Solved

How do you display 16 bit bitmaps?

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VS2015 compilation and missing DLLs 9 164
Should CArray be used for a list of pointers in C++? 19 120
best sources to up-to-date in C++? 8 91
Least Squares Curve Fitting 4 99
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

821 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