Board index » cppbuilder » Drawing on JPEG Image

Drawing on JPEG Image

Hi,

I've just installed TJPEG for BCB3, and it's loading JPEGs into a
TImage correctly. However, in my app I need to subsequently draw on
the TImage, and this no longer works, since the image isn't a bitmap.
Is there a simple way to convert the loaded JPEG to a bitmap, either
in-place or to another TImage etc?

Thanks!

 

Re:Drawing on JPEG Image


Have a look at this site:
http://www.efg2.com/lab/Graphics/BMPJPG.htm

I haven't looked closely at this particular set of source, but I have
found a lot of solutions on the efg2 site.

Quote
Michael Warner wrote:

> Hi,

> I've just installed TJPEG for BCB3, and it's loading JPEGs into a
> TImage correctly. However, in my app I need to subsequently draw on
> the TImage, and this no longer works, since the image isn't a bitmap.
> Is there a simple way to convert the loaded JPEG to a bitmap, either
> in-place or to another TImage etc?

> Thanks!

Re:Drawing on JPEG Image


Quote
Michael Warner wrote:

> I've just installed TJPEG for BCB3, and it's loading JPEGs into a
> TImage correctly. However, in my app I need to subsequently draw on
> the TImage, and this no longer works, since the image isn't a bitmap.
> Is there a simple way to convert the loaded JPEG to a bitmap, either
> in-place or to another TImage etc?

There may be a better way, and if there is, I'd love to hear about it.  The
Bitmap property of TJPEGImage is protected.  The JPEG is rendered on
the bitmap canvas.  To convert the bitmap back to JPEG, you need to call
Compress().  I've resorted to this ugliness in the past:

In the header:

class THackedJPEGImage:public TJPEGImage
{
  friend class TForm1;

Quote
};

In the source:

((THackedJPEGImage*)(Image1->Picture->Graphic))->Bitmap->
                                              Canvas->Rectangle(10, 10, 30,
30);
Image1->Refresh();
((TJPEGImage *)Image1->Picture->Graphic)->Compress();
Image1->Picture->SaveToFile("c:\\test.jpg");

I wasn't sure if you wanted to save the altered TImage.

I guess maybe you could publish the read-only Bitmap property in a derived
class or something.

Other Threads