Solved

How do you display 16 bit bitmaps?

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

737 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