Overlay one graphic onto another...

Overlay one graphic onto another...

Post by Tiro Ors » Fri, 27 Jun 2003 13:09:52



Hi.

What's the best way to overlay one graphic onto another (without displaying
the graphic itself)?

Would I create a TBitmap and draw graphic #1, then the overlay (most of
which is transparent), then save it?

And, if the first is a JPG, how would that impact anything?

Thanks,
Tiro Orsa

 
 
 

Overlay one graphic onto another...

Post by Jens Grusche » Fri, 27 Jun 2003 14:50:24


Quote:> Would I create a TBitmap and draw graphic #1, then the overlay (most of
> which is transparent), then save it?

Right. Something like

NewBitmap := TBitmap.Create;
try
  NewBitmap.PixelFormat := pf24bit; // if you like it this way
  NewBitmap.Width := Image1.Width;
  NewBitmap.Height := Image1.Height;
  NewBitmap.Canvas.Draw(0, 0, Image1);
  NewBitmap.Canvas.Draw(X, Y, Image2);
  NewBitmap.SaveToFile(...);
finally
  NewBitmap.Free;
end;

Quote:> And, if the first is a JPG, how would that impact anything?

Image1 can be a TBitmap or a TJPegImage or any other TGraphic.

Make sure Image2 has some transparency.

Jens

 
 
 

Overlay one graphic onto another...

Post by Tiro Ors » Sat, 28 Jun 2003 06:20:18


Jens: Thanks for replying...

How would I then resave it as a JPG?  The TJpegImage appears to not have a
Canvas to draw upon... as I was trying to make the new bitmap actually a new
JPG.

Thanks,
Tiro


Quote:> > Would I create a TBitmap and draw graphic #1, then the overlay (most of
> > which is transparent), then save it?

> Right. Something like

> NewBitmap := TBitmap.Create;
> try
>   NewBitmap.PixelFormat := pf24bit; // if you like it this way
>   NewBitmap.Width := Image1.Width;
>   NewBitmap.Height := Image1.Height;
>   NewBitmap.Canvas.Draw(0, 0, Image1);
>   NewBitmap.Canvas.Draw(X, Y, Image2);
>   NewBitmap.SaveToFile(...);
> finally
>   NewBitmap.Free;
> end;

> > And, if the first is a JPG, how would that impact anything?

> Image1 can be a TBitmap or a TJPegImage or any other TGraphic.

> Make sure Image2 has some transparency.

> Jens

 
 
 

Overlay one graphic onto another...

Post by Tiro Ors » Sat, 28 Jun 2003 07:27:36


Actually - I got it...

I:
1. loaded the original
2. loaded the overlay
3. assigned the original to a bitmap
4. drew the overlay onto the bitmap
5. assigned the bitmap to a new jpegimage
6. saved to file the jpegimage.

If this process is inefficient or can be improved, please let me know, but
this does work.
Thanks!
-Tiro


> Jens: Thanks for replying...

> How would I then resave it as a JPG?  The TJpegImage appears to not have a
> Canvas to draw upon... as I was trying to make the new bitmap actually a
new
> JPG.

> Thanks,
> Tiro



> > > Would I create a TBitmap and draw graphic #1, then the overlay (most
of
> > > which is transparent), then save it?

> > Right. Something like

> > NewBitmap := TBitmap.Create;
> > try
> >   NewBitmap.PixelFormat := pf24bit; // if you like it this way
> >   NewBitmap.Width := Image1.Width;
> >   NewBitmap.Height := Image1.Height;
> >   NewBitmap.Canvas.Draw(0, 0, Image1);
> >   NewBitmap.Canvas.Draw(X, Y, Image2);
> >   NewBitmap.SaveToFile(...);
> > finally
> >   NewBitmap.Free;
> > end;

> > > And, if the first is a JPG, how would that impact anything?

> > Image1 can be a TBitmap or a TJPegImage or any other TGraphic.

> > Make sure Image2 has some transparency.

> > Jens

 
 
 

Overlay one graphic onto another...

Post by Jens Grusche » Sat, 28 Jun 2003 17:03:58


Quote:> 1. loaded the original
> 2. loaded the overlay
> 3. assigned the original to a bitmap
> 4. drew the overlay onto the bitmap
> 5. assigned the bitmap to a new jpegimage
> 6. saved to file the jpegimage.

> If this process is inefficient or can be improved, please let me know, but
> this does work.

No, that's the only way. You can draw onto a TBitmap, but you cannot draw
onto a TJPegImage. JPeg images have to be compressed, which only works for a
whole graphic (an array of pixel data like TBitmap is), but not for drawing
directly (in a compressed way). Of course technically it would be possible
to have something like TJPegImage with a canvas, but that would mean you
would have to hold the pixel data somewhere (what would result in something
like a TJPegImage with a built in TBitmap), and the advantage of TJPegImage
would be lost (especially when there is not need for drawing operations,
only displaying a JPeg etc.).

Jens

 
 
 

Overlay one graphic onto another...

Post by Tiro Ors » Sun, 29 Jun 2003 04:16:10


Makes Sense...
Thanks Jens!
-Tiro


Quote:> > 1. loaded the original
> > 2. loaded the overlay
> > 3. assigned the original to a bitmap
> > 4. drew the overlay onto the bitmap
> > 5. assigned the bitmap to a new jpegimage
> > 6. saved to file the jpegimage.

> > If this process is inefficient or can be improved, please let me know,
but
> > this does work.

> No, that's the only way. You can draw onto a TBitmap, but you cannot draw
> onto a TJPegImage. JPeg images have to be compressed, which only works for
a
> whole graphic (an array of pixel data like TBitmap is), but not for
drawing
> directly (in a compressed way). Of course technically it would be possible
> to have something like TJPegImage with a canvas, but that would mean you
> would have to hold the pixel data somewhere (what would result in
something
> like a TJPegImage with a built in TBitmap), and the advantage of
TJPegImage
> would be lost (especially when there is not need for drawing operations,
> only displaying a JPeg etc.).

> Jens