Bitmap resize results in corrupt TPicture.SaveToFile

I had the same problem. Am I correct in saying that if you open it in
you Delphi program again or in Windows Paint then it looks OK? Does it
also only happen with pictures that don't define all the colours in the

If the answer to both of these is yes then I think it is the same as the
problem I had. The problem is with Delphi's SaveToFile routine for
TBitmaps. It assumes that a bmp defines all the colours in a palette.
For example you might have an 8 bit picture (256 colours) but only, say,
200 colours are defined. Then Delphi assumes that you have defined 256
colours and sets some addresses of areas in the file accordingly so they
are wrong. I assume the reason that it still opens in Delphi and Paint
is that they don't bother using these addresses.

I fixed this by overriding some routine but I can't remember what it was
and the code is at home. I'll have a look tonight and let you know
tomorrow (if someone else hasn't already).

In article <>, John J Mackey <>

>A question for the experts.  The past 2 weeks I have been tracking
>down a annoying bug in my software and finally isolated it.  To describe
>it, here's a brief outline of the code (I'm using Delphi 3):

>    // Let the user change the canvas size in runtime
>    image1.picture.bitmap.height := ix;
>    image1.picture.bitmap.width := iy;
>followed by
>    // Save it to disk
>    image1.picture.savetofile(sOutFile);

>I've found that on certain computers, when the above functions are
>executed with certain values of "ix" and "iy" (particularly large
>ones), a corrupt BMP is saved to disk.  If you look at the saved
>BMP in PaintShop Pro you see a "split" image (horizontally
>unsynchronized).  When it's loaded in the application in runtime
>using TPicture.LoadFromFile(), then the application crashes (GPF's).

>By omitting the first 2 lines, the problems do not occur.

>Am I correct in concluding that I'm violating the integrity of the
>TBitmap structure by changing its height/width property in runtime?
>What is the safest way I can accomplish this without corrupting the
>TBitmap structure?

>Changing the TImage.height/width appears to simply change the "framing"
>of the TBitmap -- the bitmap size, which is more important, remains
>unchanged.  The TPicture.height/width offers no help, either, since
>it is a read-only property.

>Thanks much.


Ian Dunn           

Polyhedron Software Ltd.        
Programs for Programmers - QA, Compilers, Graphics

************ Visit our Web site on ************