Board index » delphi » Bitmap.SaveToFile doesn't work??

Bitmap.SaveToFile doesn't work??

Hello List

I have a problem with bitmap.savetofile in D4. When I create a bitmap, draw
on its canvas and then saves it with the savetofile method, an illegal bmp
is written (i.e I can't open it in a graphics program or load it with
bitmap.loadfromfile).

It is not only the new program I am writing that produces the error, also my
old programs and the D4 demo-app graphex as well.

The strange thing is that if I load an existing image and draws on that, it
is saved as it should. I can also assign the bitmap to a TJPEGImage and save
it that way.

Hope someone can help

Carsten

Below is a code sample that produces an illegal BMP

procedure TForm1.SpeedButton1Click(Sender: TObject);
var bitmap : Tbitmap;
begin
  bitmap := TBitmap.Create;
  try
    bitmap.height := 600;
    bitmap.width := 400;
    bitmap.Canvas.brush.color := clRed;
    bitmap.Canvas.brush.style := bsDiagCross;
    bitmap.Canvas.Ellipse(0, 0, bitmap.Width, bitmap.Height);
    bitmap.savetofile('MyBMP.bmp');
  finally
    bitmap.free;
  end;
end;

 

Re:Bitmap.SaveToFile doesn't work??


Hi Carsten!

Quote
CAB wrote in message ...
>Below is a code sample that produces an illegal BMP

What program is saying the BMP is illegal?
It works for me in high color mode.  Are you in 256 color mode?

Quote
>  bitmap := TBitmap.Create;
>  try
>    bitmap.height := 600;
>    bitmap.width := 400;

When you don't specify a PixelFormat here, I think you get pfDevice, which is whatever your current display mode is.

efg
_________________________________
efg's Computer Lab:       www.efg2.com/lab
Delphi Books:  www.efg2.com/lab/TechBooks/Delphi.htm

Earl F. Glynn     E-Mail:  EarlGl...@att.net
Overland Park, KS  USA

Re:Bitmap.SaveToFile doesn't work??


Hi Earl

Thanks for your answer

Quote
>It works for me in high color mode.  Are you in 256 color mode?

No, I'm in Hi Color as well. I did not expect the code to be wrong though,
as even programs I haven't written myself (e.g. the graphex demo) produces
the error.

Quote
>What program is saying the BMP is illegal?

Any program that is able to read a bmp I guess. I have tried LView and Corel
Photopaint.

It is very mysterious, it has always worked perfectly, but from one day to
the next I wasn't able to save as bmp's. I have even tried to reinstall
Delphi without result.

Could it be something with my system?

Regards

Carsten

Re:Bitmap.SaveToFile doesn't work??


Quote
CAB wrote in message ...
>No, I'm in Hi Color as well. I did not expect the code to be wrong though,
>as even programs I haven't written myself (e.g. the graphex demo) produces
>the error.

>>What program is saying the BMP is illegal?

>Any program that is able to read a bmp I guess. I have tried LView and Corel
>Photopaint.

>It is very mysterious, it has always worked perfectly, but from one day to
>the next I wasn't able to save as bmp's. I have even tried to reinstall
>Delphi without result.

>Could it be something with my system?

If the same file works one day but not another, that's a bit strange.
Perhaps that might be something with your system.

But, I used your code and it works with any program that accepts 24-bit color.
But one of my programs and the MS PhotoEditor doesn't like the pf15bit
file created in high color mode.  I'd suggest assigning Bitmap.PixelFormat
:= pf24bit.  The file will be a little bigger, but almost every program should
be able to handle that.  Give that a try.

efg
_________________________________
efg's Computer Lab:       www.efg2.com/lab
Delphi Books:  www.efg2.com/lab/TechBooks/Delphi.htm

Earl F. Glynn     E-Mail:  EarlGl...@att.net
Overland Park, KS  USA

Other Threads