Recent

Author Topic: Bitmaps width 32bit Colordepth  (Read 5751 times)

hammster12

  • New member
  • *
  • Posts: 5
Bitmaps width 32bit Colordepth
« on: October 31, 2010, 02:26:54 pm »
I would like to write a program for Windows CE 5.0.
As I begun with use a bitmap with 32bit color than I realised that there is a memoryleak.
When I use a 16bit color bitmap than I haven't got this problem.

I would like to show the sourcecode of my program:
I use an image, a button for exit and a timer.

Code: [Select]
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  ExtCtrls, StdCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button3: TButton;
    Image1: TImage;
    ImageList1: TImageList;
    Timer1: TTimer;
    procedure Button3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;
  Bitmap01:tBitmap;

implementation

{ TForm1 }

procedure TForm1.Button3Click(Sender: TObject);
begin
  form1.Close;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
     Bitmap01:=tbitmap.Create;
     Bitmap01.Width:=100;
     Bitmap01.Height:=100;
     Bitmap01.PixelFormat:=pf32bit;
     Bitmap01.Canvas.Pen.Color:=clred;
     Bitmap01.Canvas.Pen.Width:=3;
     Bitmap01.Canvas.Brush.Color:=clyellow;
     Bitmap01.Canvas.FillRect(2,2,98,98);
     timer1.Enabled:=true;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
     image1.Canvas.Draw(random(100),random(84),Bitmap01);
end;

initialization
  {$I unit1.lrs}

end.
           

What do I wrong?

Thank you for your help in advance!

Laksen

  • Hero Member
  • *****
  • Posts: 624
    • J-Software
Re: Bitmaps width 32bit Colordepth
« Reply #1 on: October 31, 2010, 03:37:58 pm »
Where do you call Bitmap01.Free? ;)

hammster12

  • New member
  • *
  • Posts: 5
Re: Bitmaps width 32bit Colordepth
« Reply #2 on: October 31, 2010, 05:38:38 pm »
You are right!
I forget to write before form1.close; the bitmap01.free.
But unfortunately it is not the main problem:
When I use Bitmap01.PixelFormat:=pf32bit; then my program will use up the whole systemmemory. It happens always at
image1.Canvas.Draw(....); piece by piece.
(1. timer event: 100x100x4 bytes remain in memory
 2. timer event: 100x100x4+100x100x4 bytes
 3. timer event: .... and so on)
When I use Bitmap01.PixelFormat:=pf16bit; then I haven't got this problem.
But I want to use transparent images which must have a 32bit colordepth (24bit color + 8bit alpha)

I hope it's understandable, I'm sorry for my pure English!

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2496
Re: Bitmaps width 32bit Colordepth
« Reply #3 on: October 31, 2010, 11:35:17 pm »
maybe some internal (widgetset) error. Please bugrep (and if possible with small demo code)
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker