Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

24 bit BMP on 256 color display

Posted on 1997-09-18
6
Medium Priority
?
284 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
[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
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 300 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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

705 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