Board index » delphi » Drawing lines on top of JPEG image

Drawing lines on top of JPEG image

I need to draw lines on top of a JPEG image, but when I try to use
Image1.Canvas.LineTo (x,y) I get the error message 'Can only modify an
image if it contains a bitmap' (Delphi 3).
I've also tried putting a TPaintBox on top of the image, but lines drawn
on the PaintBox1.Canvas won't 'stick' when the window needs to be redrawn
(due to resizing of other programs that cover the window).

Is there ANY way, apart from converting all JPEG files to BMP files, I
can get (diagonal) lines on top of my image, that get updated whenever
the window is redrawn?
--
Peter Bremer
  PLEASE NOTE: this e-mail address has been altered
  to stop spam!  Remove the 'nospam!' part to get
  my real address!!

 

Re:Drawing lines on top of JPEG image


In article <MPG.10f44fb7af408e41989...@news.xs4all.nl>,
  nospam!...@dds.nl (Peter) wrote:

Quote
> I need to draw lines on top of a JPEG image, but when I try to use
> Image1.Canvas.LineTo (x,y) I get the error message 'Can only modify an
> image if it contains a bitmap' (Delphi 3).
> I've also tried putting a TPaintBox on top of the image, but lines drawn
> on the PaintBox1.Canvas won't 'stick' when the window needs to be redrawn
> (due to resizing of other programs that cover the window).

> Is there ANY way, apart from converting all JPEG files to BMP files, I
> can get (diagonal) lines on top of my image, that get updated whenever
> the window is redrawn?

       If you want to use an image you could Assign your JPEG to a
bitmap and draw on it:

theJPEG.LoadFromFile('whatever.jpg');
Image1.Picture.Bitmap.Assign(theJPEG);
theJPEG.Free;

         Any time you use a paintbox you need to do _all_ your
drawing in the paintbox's OnPaint event handler. Like you
might have a TBitmap B, and the OnPaint handler would be
something like

with (Sender as TPaintBox).Canvas do
begin
  Draw(0, 0, B);
  MoveTo(0, 0);
  LineTo(100, 100);
end;

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    

Re:Drawing lines on top of JPEG image


I assume, that you use JPeg library included with D3. Try this: create
TJpegImage object and load jpg image into it. Then assign it to bitmap:
  var   JPegImage: TJpegImage;
            Bitmap: TBitmap;
...................
   Bitmap.Assign( JPegImage );

    Now you have a bitmap instead of jpeg ( can be used to convert jpeg into
bitmap and vice versa to ). Don't forget to include JPeg under uses clause.

                                                            Tomaz

Quote
Peter wrote in message ...
>I need to draw lines on top of a JPEG image, but when I try to use
>Image1.Canvas.LineTo (x,y) I get the error message 'Can only modify an
>image if it contains a bitmap' (Delphi 3).
>I've also tried putting a TPaintBox on top of the image, but lines drawn
>on the PaintBox1.Canvas won't 'stick' when the window needs to be redrawn
>(due to resizing of other programs that cover the window).

>Is there ANY way, apart from converting all JPEG files to BMP files, I
>can get (diagonal) lines on top of my image, that get updated whenever
>the window is redrawn?
>--
>Peter Bremer
>  PLEASE NOTE: this e-mail address has been altered
>  to stop spam!  Remove the 'nospam!' part to get
>  my real address!!

Re:Drawing lines on top of JPEG image


Hi, Is there a way I can invalidate an area on a paintbox component rather
than the entire area. I haven't had any luck with InvalidateRect although
InvertRect shows the correct area that I'm trying to invalidate.

Cheers,
Terry

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    

Other Threads