Board index » delphi » strange thing with bmp

strange thing with bmp

Hello Everybody,

Simple code :
// -----
procedure TForm1.Button1Click(Sender: TObject);
var bmp: TBitmap;
begin
   bmp := TBitmap.Create;
   bmp.LoadFromFile(ExtractFilePath(Application.ExeName)+'bmp1.bmp');
   bmp.SaveToFile(ExtractFilePath(Application.ExeName)+'bmp2.bmp');
   bmp.Free;
end;
// -----

But surprisingly I get a file size 921654 instead of 921658 bytes,
blue instead of red, red instead of green and some right shift of the
picture. The original bmp was created with TFastBMP component if
somebody knows it. It really damned. Please help if somebody knows
what the problem is...
Regards, Thanx in advance, Alex.

 

Re:strange thing with bmp


Also,  What PixelFormat are you saving out at?
I have never heard of TFastBitmap,  but if it is somehow different from
TBitmap,   then perhaps it has it's own Load and Save methods.

Regards

Stan

Re:strange thing with bmp


Can you post the offending bitmap to attachments?

regards

Stan.

Re:strange thing with bmp


The only thing I found on this TFastBitmap issue is
(http://www.elists.org/pipermail/delphi/2000-May/004083.html) but I don't
think that is it but...
1. Try PixelFormat...maybe you saved in a different pixel format
2. Size diff and color diff and right shift: the problem could be a coded
image (some sort of compression).

--
Liran Shahar
Com-N-Sense (www.com-n-sense.com)

Re:strange thing with bmp


it looks like a palette problem : remember to set pixelformat to 24 bit if
you do not want palette problems .

"khomalex" <khoma...@criso.com> ha scritto nel messaggio
news:k9go3ukr3km125lm6d64qtfas0pe1gk7ne@4ax.com...

Quote
> Hello Everybody,

> Simple code :
> // -----
> procedure TForm1.Button1Click(Sender: TObject);
> var bmp: TBitmap;
> begin
>    bmp := TBitmap.Create;
>    bmp.LoadFromFile(ExtractFilePath(Application.ExeName)+'bmp1.bmp');
>    bmp.SaveToFile(ExtractFilePath(Application.ExeName)+'bmp2.bmp');
>    bmp.Free;
> end;
> // -----

> But surprisingly I get a file size 921654 instead of 921658 bytes,
> blue instead of red, red instead of green and some right shift of the
> picture. The original bmp was created with TFastBMP component if
> somebody knows it. It really damned. Please help if somebody knows
> what the problem is...
> Regards, Thanx in advance, Alex.

Re:strange thing with bmp


Another possibility is an interaction with your current video settings.  As
Liran suggested set PixelFormat and HandleType before doing the save to force
to a "standard" bitmap.
Quote
Liran Shahar wrote:
> The only thing I found on this TFastBitmap issue is
> (http://www.elists.org/pipermail/delphi/2000-May/004083.html) but I don't
> think that is it but...
> 1. Try PixelFormat...maybe you saved in a different pixel format
> 2. Size diff and color diff and right shift: the problem could be a coded
> image (some sort of compression).

> --
> Liran Shahar
> Com-N-Sense (www.com-n-sense.com)

Re:strange thing with bmp


Sounds like there's a bug with the offending bitmap: I've encountered a
similar thing  where there was an extra entry in the colour table (257
colour bitmap ?!!), and the VCL code expected the start of the pixel data
to be in the "right place" - explaining the right shift, and the colour
problems. The bitmap header format does specify an offset to the pixel
data, which the VCL doesn't use - and hence when you re-save the bitmap
changes size.

If the re-loaded bitmap after saving looks the same, this could be it, as
the VCL save bitmaps correctly.

You can fix the bitmap loading code by overriding the LoadFromStream ina
descendant class of TBitmap, and using that to LoadFormFile.

HTH

Patrick

Quote
khomalex wrote:
> Hello Everybody,

> Simple code :
> // -----
> procedure TForm1.Button1Click(Sender: TObject);
> var bmp: TBitmap;
> begin
>    bmp := TBitmap.Create;
>    bmp.LoadFromFile(ExtractFilePath(Application.ExeName)+'bmp1.bmp');
>    bmp.SaveToFile(ExtractFilePath(Application.ExeName)+'bmp2.bmp');
>    bmp.Free;
> end;
> // -----

> But surprisingly I get a file size 921654 instead of 921658 bytes,
> blue instead of red, red instead of green and some right shift of the
> picture. The original bmp was created with TFastBMP component if
> somebody knows it. It really damned. Please help if somebody knows
> what the problem is...
> Regards, Thanx in advance, Alex.

Other Threads