Solved

How do you display 16 bit bitmaps?

Posted on 1997-08-30
1
305 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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…
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.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

707 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