Solved

24 bit BMP on 256 color display

Posted on 1997-09-18
6
262 Views
Last Modified: 2010-04-03
When I use the standard image component to stick a 24 bit BMP file on a form the picture looks awful (like its only 16 colors). Is there a trick to make it look nicer without going to the hassle of converting it to a 256 color BMP first?

ta chris
0
Comment
Question by:chrishart
  • 3
  • 3
6 Comments
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1345515
I once got around the problem like this:  (You convert the bitmap to 256 in Delphi, not the physical bitmap on disk.  The original bitmap on disk in my case was a 24 bit bitmap too.)

procedure TForm1.LoadBitmap;
var
  Bmp: TBitmap;
begin
  Bmp := TBitmap.Create;
  Bmp.LoadFromFile('C:\Temp\Test.bmp');
  Bmp.PixelFormat := pf8bit;
  Image1.Picture.Assign(Bmp);
  Bmp.Free;
end;

0
 

Author Comment

by:chrishart
ID: 1345516
Thanks for the answer, it looked like it should do the trick.
I tried your code out but Sadly C++Builder does not seem to support
PixelFormat so it didn't work :-(
I'm sorry I didn't mention that I was using Builder, things are usually
the same.
It seems C++Builder's TBitmap is perhaps based on an old version of Delphi?

Thanks Chris
0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1345517
Delphi's code for SetPixelFormat is below.  You should be able to convert it easily because it mostly deals with palettes and Wnidows API calls.

TPixelFormat = (pfDevice, pf1bit, pf4bit, pf8bit, pf15bit, pf16bit, pf24bit, pf32bit, pfCustom);

procedure TBitmap.SetPixelFormat(Value: TPixelFormat);
const
  BitCounts: array [pf1Bit..pf32Bit] of Byte = (1,4,8,16,16,24,32);
var
  DIB: TDIBSection;
  Pal: HPalette;
  DC: HDC;
begin
  if Value = GetPixelFormat then Exit;
  case Value of
    pfDevice:
      begin
        HandleType := bmDDB;
        Exit;
      end;
    pfCustom: InvalidGraphic(SInvalidPixelFormat);
  else
    FillChar(DIB, sizeof(DIB), 0);
    DIB.dsbm := FImage.FDIB.dsbm;
    with DIB, dsbm, dsbmih do
    begin
      bmBits := nil;
      biSize := sizeof(DIB.dsbmih);
      biWidth := bmWidth;
      biHeight := bmHeight;
      biPlanes := 1;
      biBitCount := BitCounts[Value];
      Pal := FImage.FPalette;
      case Value of
        pf4Bit: Pal := SystemPalette16;
        pf8Bit:
          begin
            DC := GDICheck(GetDC(0));
            Pal := CreateHalftonePalette(DC);
            ReleaseDC(0, DC);
          end;
        pf16Bit:
          begin
            biCompression := BI_BITFIELDS;
            dsBitFields[0] := $F800;
            dsBitFields[1] := $07E0;
            dsBitFields[2] := $001F;
          end;
      end;
      CopyImage(Handle, Pal, DIB);
      PaletteModified := Pal <> 0;
      Changed(Self);
    end;
  end;
end;

0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:chrishart
ID: 1345518
Thanks JimBob for your comment, that looks good to me, can you make it an answer so I can award you your points and close the topic!

Thanks very much Chris
0
 
LVL 5

Accepted Solution

by:
JimBob091197 earned 100 total points
ID: 1345519
I hope it works ok for you...
0
 

Author Comment

by:chrishart
ID: 1345520
Sorry about the delay and thanks again

Chris
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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

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