Wrong PixelFormat read by TBitmap.
Original Reporter info from Mantis: sainimu78
-
Reporter name: fantangshan
Original Reporter info from Mantis: sainimu78
- Reporter name: fantangshan
Description:
Get wrong PixelFormat by TBitmap if it reads a 8bits .bmp file.
Just paste the code below on Unit1.pas of a new Application project.
Steps to reproduce:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls;
type
TMyPng = class(TBitmap)
public
function GetData: PByte;
end;
{ TForm1 }
TForm1 = class(TForm)
Button1:TButton;
Panel1:TPanel;
procedure Button1Click(Sender:TObject);
procedure Panel1Paint(Sender:TObject);
private
{ private declarations }
public
{ public declarations }
bmp:TMyPng;
fCnt:Char;
end;
var
Form1: TForm1;
implementation
function TMyPng.GetData: PByte;
begin
result := GetRawImagePtr^.Data;
end;
{$R *.lfm}
{ TForm1 }
procedure TForm1.Panel1Paint(Sender:TObject);
var
pDat:PByte;
pf:TPixelFormat;
begin
bmp := TMyPng.Create;
bmp.LoadFromFile('c:\some_8_bits.bmp');
pf := bmp.PixelFormat;//why 24bits?
FillChar(bmp.GetData^, bmp.Width*bmp.Height, fCnt);
Panel1.Canvas.Draw(0, 0, bmp);
fCnt := Char(Integer(fCnt) + 1);
bmp.Free;
end;
procedure TForm1.Button1Click(Sender:TObject);
begin
Panel1Paint(Sender);
end;
end.
Mantis conversion info:
- Mantis ID: 30509
- OS: win32
- OS Build: win7
- Build: 1.6
- Platform: i386
- Version: 1.6
- Fixed in revision: r56872 (#84369842)