Board index » delphi » Bitmaps, JPEGs and memory

Bitmaps, JPEGs and memory

Using Delphi 3 I'm making a screen saver that will use JPEG images
saved at a 800x600 resolution. I want to have the entire image fit in
whatever screen resolution the user happens to be using and to then
draw it using special effects. I came up with the code to do just this
(and it works), but am now worried about how much memory this will
use. Paint Shop Pro shows an image at 800x600 uses 2.7 Meg of memory.
Does this mean that the code below could possibly need 8.1 Meg *just*
for the images?

Here is very basically the method I came up with:

  ...
  JPGImg := TJPEGImage.Create;
  Bmp := TBitmap.Create; Bmp2 := TBitmap.Create;
  JPGImg.LoadFromFile('mypicture.jpg');
  Bmp.Assign(JPGImg);
  JPGImg.Free;
  Bmp2.Height := Screen.Height; Bmp2.Width := Screen.Width;
  Bmp2.Canvas.StretchDraw(rect(0, 0, Screen.Width, Screen.Height),
Bmp);

  with Form1.Canvas do
    begin
      {here I do special effects using Bmp2 which is now the right
size}
      ...

Russ

 

Re:Bitmaps, JPEGs and memory


Quote
In article <34de77ab.29440...@forums.borland.com>, r...@irwinware.com wrote:
>Using Delphi 3 I'm making a screen saver that will use JPEG images
>saved at a 800x600 resolution. I want to have the entire image fit in
>whatever screen resolution the user happens to be using and to then
>draw it using special effects. I came up with the code to do just this
>(and it works), but am now worried about how much memory this will
>use. Paint Shop Pro shows an image at 800x600 uses 2.7 Meg of memory.
>Does this mean that the code below could possibly need 8.1 Meg *just*
>for the images?

>Here is very basically the method I came up with:

>  ...
>  JPGImg := TJPEGImage.Create;
>  Bmp := TBitmap.Create; Bmp2 := TBitmap.Create;
>  JPGImg.LoadFromFile('mypicture.jpg');
>  Bmp.Assign(JPGImg);
>  JPGImg.Free;
>  Bmp2.Height := Screen.Height; Bmp2.Width := Screen.Width;
>  Bmp2.Canvas.StretchDraw(rect(0, 0, Screen.Width, Screen.Height),
>Bmp);

>  with Form1.Canvas do
>    begin
>      {here I do special effects using Bmp2 which is now the right
>size}

For a JPEG image multiple the image hight * with * 3 to get the number of
bytes required to display the image. Buffering is usually required so that
during decompression you have to double this.

John - N8086N
Organizer and Executive Vice President of the
"Vast Right-Wing {*word*97}"
The Vast Right-Wing {*word*97} is now on-line at
http://home.att.net/~miano/{*word*97}.htm
------------------------------------------------
EMail Address:
|m.i.a.n.o @    |
|c.o.l.o.s.s.e.u.m.b.u.i.l.d.e.r.s.|
|c.o.m.|

Full Name:
-------------------
-J.o.h.n?M.i.a.n.o-
-------------------

Re:Bitmaps, JPEGs and memory


I compute 800 x 600 x 3 (# of bytes per pixle for true color) yields 1.44
meg for this size bitmap, not quite the 2.7 you mentioned.  But, you are
correct... each bitmap in memory takes space and 3 of teh pupiies at 800 x
600 will occupy about 4.5 meg.

Quote
r...@irwinware.com wrote:
> Using Delphi 3 I'm making a screen saver that will use JPEG images
> saved at a 800x600 resolution. I want to have the entire image fit in
> whatever screen resolution the user happens to be using and to then
> draw it using special effects. I came up with the code to do just this
> (and it works), but am now worried about how much memory this will
> use. Paint Shop Pro shows an image at 800x600 uses 2.7 Meg of memory.
> Does this mean that the code below could possibly need 8.1 Meg *just*
> for the images?

> Here is very basically the method I came up with:

>   ...
>   JPGImg := TJPEGImage.Create;
>   Bmp := TBitmap.Create; Bmp2 := TBitmap.Create;
>   JPGImg.LoadFromFile('mypicture.jpg');
>   Bmp.Assign(JPGImg);
>   JPGImg.Free;
>   Bmp2.Height := Screen.Height; Bmp2.Width := Screen.Width;
>   Bmp2.Canvas.StretchDraw(rect(0, 0, Screen.Width, Screen.Height),
> Bmp);

>   with Form1.Canvas do
>     begin
>       {here I do special effects using Bmp2 which is now the right
> size}
>       ...

> Russ

--
Wayne Herbert
Manager, Computer Products
Key Maps, Inc.
1411 West Alabama
Houston, TX  77006

Vox:  713.522.7949
Fax:  713.521.3202
Email:  wherb...@rice.edu

"Why is it only drug dealers and software developers call their clients
'users'?"

Re:Bitmaps, JPEGs and memory


On Mon, 09 Feb 1998 09:21:08 -0600, Wayne Herbert

Quote
<wherb...@keymaps.com> wrote:
>I compute 800 x 600 x 3 (# of bytes per pixle for true color) yields 1.44
>meg for this size bitmap, not quite the 2.7 you mentioned.  But, you are
>correct... each bitmap in memory takes space and 3 of teh pupiies at 800 x
>600 will occupy about 4.5 meg.

The 1.44M does appear to be right (the mathematics are indisputable
<g>), although I just tried using Windows95 "System Monitor" and I
came up with 2.5M at 640x480 resolution (I'm using two bitmaps). The
surprising thing was that I only came up with 2.7M running at 800x600.
Does this mean that the 1.44M is dependent on the JPEG parameters
(800x600) that are copied to the Bitmap, and not the size of the
screen resolution?

Also, I would like to check for enough available memory on the user's
system when the program starts up but can't find the appropriate code
in Delphi 3's help files. Is there a quick and easy way to code for
this?

Thanks,

Russ

Other Threads