Board index » delphi » Bitmaps and Delphi

Bitmaps and Delphi

Hoi,

I am trying to use bitmaps in Delphi, but I don't have much
information. Can you help me with the next question?

1. When working with bitmaps in Delphi, I often have the problem of
losing system resources. I really do not know what I am doing wrong?
2. Can you tell me where I can find general info about bitmaps and
actions on it ? (Internet, magazines, books)
3. I would like to use compression techniques on the ( limited color
bitmaps). Are there techniques directly definable in Delphi ??????

THANKS!!!!!

Brenda.

 

Re:Bitmaps and Delphi


Quote
Tele Atlas wrote:

> Hoi,

> I am trying to use bitmaps in Delphi, but I don't have much
> information. Can you help me with the next question?

> 1. When working with bitmaps in Delphi, I often have the problem of
> losing system resources. I really do not know what I am doing wrong?

        Hard to tell what you're doing wromg without seeing what you're
doing. (Is there a Free matching every Create? And if yes is there something
in between that could be "orphaning" pointers? What would that be?
Can't tell - what does your code look like???)

--
David Ullrich
Sig file accidentally deleted - sorry.

Re:Bitmaps and Delphi


Quote
>>>>> "Tele" == Tele Atlas <i...@teleatlas.be> writes:

 Tele> Hoi, I am trying to use bitmaps in Delphi, but I don't have
 Tele> much information. Can you help me with the next question?

 Tele> 1. When working with bitmaps in Delphi, I often have the
 Tele> problem of losing system resources. I really do not know what I
 Tele> am doing wrong?  

I had a program running under win95, that would, in the end, eat all
GDI ressources from Windows.

This was because I was using an example from the docs, that went something
like this (I think it was TImage);

(Image1 is on the form);

procedure somebuttonclick(sender : TObject(;
var
  bitmap : TBitMap;
begin
  bitmap:=TBitMap.Create;
  bitmap.LoadFromFile(filename);
  image.picture.bitmap:=bitmap;
  {bitmap.free; // <- this is neccesary! }
end;

the docs state that you ___don't___ need the bitmap.free statement,
because the image component will free the bitmap eventually.
This is partly true, but when you assign the bitmap to the image
component, an internal counter in the bitmap is inc, and
therefore you need to free it. (I read through the vcl graphics.pas
source code to find out ;-( )

I don't know if you have anything like this in your code, but I
found not less then 4 different examples in the docs, that
were errounous on this.

Hope it helps. It sure helped me!

Mads

--
+----------------------------------------------------------------------+
|  Mads Bondo Dydensborg.   Student at DIKU,  Copenhagen - Denmark.    |
|  Email: mads...@diku.dk   www: http://www.diku.dk/students/madsdyd/  |
+----------------------------------------------------------------------+

Re:Bitmaps and Delphi


Quote
>3. I would like to use compression techniques on the ( limited color
>bitmaps). Are there techniques directly definable in Delphi ??????

There is a component caled TCompress available to do this.  Contact
the creator Peter Hyde (Pe...@spis.co.nz) for more info.

Wade

Re:Bitmaps and Delphi


mads...@diku.dk (Mads Bondo Dydensborg) wrote:

Quote
>procedure somebuttonclick(sender : TObject(;
>var
>  bitmap : TBitMap;
>begin
>  bitmap:=TBitMap.Create;
>  bitmap.LoadFromFile(filename);
>  image.picture.bitmap:=bitmap;
>  {bitmap.free; // <- this is neccesary! }
>end;
>the docs state that you ___don't___ need the bitmap.free statement,
>because the image component will free the bitmap eventually.
>This is partly true, but when you assign the bitmap to the image
>component, an internal counter in the bitmap is inc, and
>therefore you need to free it. (I read through the vcl graphics.pas
>source code to find out ;-( )

The above example is ok, as long as you don't assign something else to
the Image object.  If you were to hit the SomeButton above twice in a
row, you would be loosing a TBitmap.  

 A better way to do this is to use Assign, and then free the bitmap.

If you created it, then you destroy it.  And, if its a local variable,
destroy it before you leave the procedure.

dk

Re:Bitmaps and Delphi


Incidentally, in delphi 2, if you do lose some objects, they will be
freed when your process ends.  In delphi 1, there is no such fall
back.

dk

Re:Bitmaps and Delphi


Quote
On Fri, 14 Jun 1996 00:09:47 GMT, dkna...@rdtech.com (Lemur) wrote:
>mads...@diku.dk (Mads Bondo Dydensborg) wrote:

>>procedure somebuttonclick(sender : TObject(;
>>var
>>  bitmap : TBitMap;
>>begin
>>  bitmap:=TBitMap.Create;
>>  bitmap.LoadFromFile(filename);
>>  image.picture.bitmap:=bitmap;
>>  {bitmap.free; // <- this is neccesary! }
>>end;

>The above example is ok, as long as you don't assign something else to
>the Image object.  If you were to hit the SomeButton above twice in a
>row, you would be loosing a TBitmap.  

> A better way to do this is to use Assign, and then free the bitmap.

image.picture.bitmap := bitmap does call Assign. That's why the call
to bitmap.free is necessary.

Quote
>If you created it, then you destroy it.  And, if its a local variable,
>destroy it before you leave the procedure.

Exactly. Since somebuttonclick creates the TBitmap object, it must
also free it. The TImage object manages its own TBitmap object.
--
Ray Lischner                              li...@tempest-sw.com
Tempest Software, Corvallis, Oregon, USA  http://www.tempest-sw.com

Re:Bitmaps and Delphi


  On Fri, 14 Jun 1996 00:09:47 GMT, dkna...@rdtech.com (Lemur) wrote:
  >mads...@diku.dk (Mads Bondo Dydensborg) wrote:
  >
  >>procedure somebuttonclick(sender : TObject(;
  >>var
  >>  bitmap : TBitMap;
  >>begin
  >>  bitmap:=TBitMap.Create;
  >>  bitmap.LoadFromFile(filename);
  >>  image.picture.bitmap:=bitmap;
  >>  {bitmap.free; // <- this is neccesary! }
  >>end;
  >
  >The above example is ok, as long as you don't assign something else to
  >the Image object.  If you were to hit the SomeButton above twice in a
  >row, you would be loosing a TBitmap.  
  >
  > A better way to do this is to use Assign, and then free the bitmap.

  image.picture.bitmap := bitmap does call Assign. That's why the call
  to bitmap.free is necessary.

Correct.

  >If you created it, then you destroy it.  And, if its a local variable,
  >destroy it before you leave the procedure.

  Exactly. Since somebuttonclick creates the TBitmap object, it must
  also free it. The TImage object manages its own TBitmap object.

Yes! There are several things that goes well together. begin - end,
create - free. But unfortynatly the docs _insists_ that you should
_not_ do the free above. I, for one, was naive enough to belive it.

But even though Image1 above manage its own bitmap, it does not
manage its own TInternalImage (or whatever). This was a reason I
kept loosing HPalette objects at a time. The docs could be so
much better here.

Anayway : The conclusion is correct, use free. To bad the docs are
totally wrong here.

And if you weant to use palettes, you should copy the palette before assinging
it to an object you will later free, if you want to keep that palette.

Mads

--
+----------------------------------------------------------------------+
|  Mads Bondo Dydensborg.   Student at DIKU,  Copenhagen - Denmark.    |
|  Email: mads...@diku.dk   www: http://www.diku.dk/students/madsdyd/  |
+----------------------------------------------------------------------+

Other Threads