Board index » cppbuilder » Drawing on a TImage's Canvas with a JPG's loaded.

Drawing on a TImage's Canvas with a JPG's loaded.

Hi,

I have a TImage with a JPG loaded. If I try to draw on the canvas with
the following "Image1->Canvas->Ellipse(iX,iY,X,Y)" I get the error "Can
only modify an image if it contains a bitmap". If I convert the JPG to a
Bitmap it works fine but the Bitmap filesizes are too large and slow do
the program. Is there anyway off writing to the Canvas of a TImage when
a JPG is laoded????

thanks,
Liam Mullane.

 

Re:Drawing on a TImage's Canvas with a JPG's loaded.


Quote
Liam Mullane wrote:

> Hi,

> I have a TImage with a JPG loaded. If I try to draw on the canvas with
> the following "Image1->Canvas->Ellipse(iX,iY,X,Y)" I get the error "Can
> only modify an image if it contains a bitmap". If I convert the JPG to a
> Bitmap it works fine but the Bitmap filesizes are too large and slow do
> the program. Is there anyway off writing to the Canvas of a TImage when
> a JPG is laoded????

The TImage must be a Bitmap in order for you to draw on.

You can convert the jpeg to to bitmap when you load it, then you'll be
able to draw on it.  If you need to save it you'll need to convert it
back to a jpeg.

#include "jpeg.hpp"

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  TJPEGImage *jpeg = new TJPEGImage();

  jpeg->LoadFromFile("shaokan.jpg");
  Image1->Picture->Bitmap->Assign(jpeg);

  Image1->Canvas->Rectangle(10, 10, 30, 30);

  jpeg->Assign(Image1->Picture->Graphic);
  jpeg->SaveToFile("test.jpg");

  delete jpeg;

Quote
}

Re:Drawing on a TImage's Canvas with a JPG's loaded.


Quote
Liam Mullane wrote:
> I have a TImage with a JPG loaded. If I try to draw on the canvas with
> the following "Image1->Canvas->Ellipse(iX,iY,X,Y)" I get the error
> "Can only modify an image if it contains a bitmap". If I convert the JPG
> to a Bitmap it works fine but the Bitmap filesizes are too large and slow
> do the program. Is there anyway off writing to the Canvas of a TImage
> when a JPG is laoded????

Some help here:
www.mers.com/merlist/borland/public/cppbuilder/graphics/7571.html

Other Threads