Thread View: borland.public.cppbuilder.multimedia
17 messages
17 total messages
Started by Mario Sernicola
Tue, 01 Jun 2004 19:23
How to draw into a jpeg image
Author: Mario Sernicola
Date: Tue, 01 Jun 2004 19:23
Date: Tue, 01 Jun 2004 19:23
26 lines
1523 bytes
1523 bytes
Hi,
I've a TImage that contains a JPEG image
I'd like to draw on it but when I try to draw a point or a line with
//--------------------------
...
tagPOINT mousepos;
GetCursorPos(&mousepos);
int x = mousepos.x - Left;
int y = mousepos.y - Top;
Timage1->Canvas->Pen->Width = 1;
Timage1->Canvas->Pen->Mode = pmNot;
Timage1->Canvas->Ellipse(x, y, x+3, y+3);
//--------------------------
a message error appears:
"Can only modify an image if it contains a bitmap"
How can I draw on TImage either if it contains a BMP or JPG???
Thanks
Mario Sernicola
Re: How to draw into a jpeg image
Author: Remy Lebeau (TeamB)
Date: Tue, 01 Jun 2004 22:23
Date: Tue, 01 Jun 2004 22:23
22 lines
1539 bytes
1539 bytes
"Mario Sernicola" <mariosernicola@nospam.libero.it> wrote in message news:40bcd795$1@newsgroups.borland.com... > Timage1->Canvas->Pen->Width = 1; <snip> > a message error appears: > > "Can only modify an image if it contains a bitmap" The error is correct. The Canvas property is only valid when the Picture contains a TBitmap. > How can I draw on TImage either if it contains a BMP or JPG??? You can't. You would have to convert the JPG into a BMP first, then draw on it, then convert it back into a JPG again. The problem is that JPG is a lossy format. The more you alter it, the more image quality it loses. Gambit
Re: How to draw into a jpeg image
Author: Mario Sernicola
Date: Wed, 02 Jun 2004 07:48
Date: Wed, 02 Jun 2004 07:48
21 lines
1755 bytes
1755 bytes
Ok, so I've to continue convert JPG into a BMP with an external software, import the BMP in my TImage component, draw on it and finally import the JPG in TImage. I need to draw on TImage canvas in order to catch vertex pixel of a polygon that describes a shape contained in TImage. When the vertex are know, I don't need BMP anymore. "Remy Lebeau (TeamB)" <gambit47.no.spam@no.spam.yahoo.com> ha scritto nel messaggio news:40bd02cb@newsgroups.borland.com... > > How can I draw on TImage either if it contains a BMP or JPG??? > > You can't. You would have to convert the JPG into a BMP first, then draw on > it, then convert it back into a JPG again. The problem is that JPG is a > lossy format. The more you alter it, the more image quality it loses. > > > Gambit > >
Re: How to draw into a jpeg image
Author: Giuliano
Date: Wed, 02 Jun 2004 09:10
Date: Wed, 02 Jun 2004 09:10
45 lines
2373 bytes
2373 bytes
On Wed, 2 Jun 2004 09:48:56 +0200, "Mario Sernicola"
<mariosernicola@nospam.libero.it> wrote:
>Ok, so I've to continue convert JPG into a BMP with an external software,
No, you can make it on the fly. For example, with BCB6 it's pretty seamless.
>I need to draw on TImage canvas in order to catch vertex pixel of a polygon
>that describes a shape contained in TImage. When the vertex are know, I
>don't need BMP anymore.
Please, take the following snippet like a starting point for your further
experiments:
#include <memory>
#include <Jpeg.hpp>
using std::auto_ptr;
void ProcessTheImage( void )
{
// crea una istanza di TJPEGImage e ci carica dentro una immagine
auto_ptr<TJPEGImage> const JPG( new TJPEGImage );
JPG->LoadFromFile( "nome del file.jpg" );
// crea una DIB e gli assegna il contenuto del JPEG precedentemente
// creato
auto_ptr<Graphics::TBitmap> const BMP( new Graphics::TBitmap );
BMP->Assign( JPG.get() );
// Aggiunge una ellisse, giusto per "sporcare" un pochino l'immagine
// originale
BMP->Canvas->Ellipse( 10, 10, 100, 200 );
// assegna di nuovo l'immagine modificata al JPEG
JPG->Assign( BMP.get() );
// Salva su file,
JPG->SaveToFile( "nome del nuovo file.jpg" );
// oppure... assegna il JPEG appena creato ad un componente TImage
Image1->Picture->Bitmap->Assign( JPG.get() );
}
Ciao
Giuliano
Re: How to draw into a jpeg image
Author: Hans Galema
Date: Wed, 02 Jun 2004 09:13
Date: Wed, 02 Jun 2004 09:13
39 lines
1997 bytes
1997 bytes
Mario Sernicola wrote:
> Ok, so I've to continue convert JPG into a BMP with an external software,
No that has not been said.
> import the BMP in my TImage component, draw on it and finally import the JPG
> in TImage.
You can just make a bitmap yourself and draw the jpg on it.
Load the jpg in Image1 and place an extra TImage Image2 on your form:
Graphics::TBitmap *bitmap = new Graphics::TBitmap;
try
{
bitmap->Width = Image1->Width;
bitmap->Height = Image1->Height;
bitmap->Canvas->Draw ( 0,0,Image1->Picture->Graphic);
Image2->Picture->Bitmap->Assign ( bitmap );
}
catch ( Exception &exception )
{
//
}
delete bitmap;
> I need to draw on TImage canvas in order to catch vertex pixel of a polygon
> that describes a shape contained in TImage. When the vertex are know, I
> don't need BMP anymore.
You can use Image 2 for that. Or, even better, bitmap->Canvas.
Hans.
Re: How to draw into a jpeg image
Author: Remy Lebeau (TeamB)
Date: Wed, 02 Jun 2004 17:57
Date: Wed, 02 Jun 2004 17:57
27 lines
1802 bytes
1802 bytes
"Mario Sernicola" <mariosernicola@nospam.libero.it> wrote in message
news:40bd8664$1@newsgroups.borland.com...
> Ok, so I've to continue convert JPG into a BMP with an external software
Assuming you are using TJPEGImage, it already knows how to convert itself
to/from a TBitmap. Just use the Assign() method, ie:
Graphics::TBitmap *bmp = new Graphics::TBitmap;
try
{
bmp->Assign(Image1->Picture->Graphic);
// alter the bmp as needed...
Image1->Picture->Graphic->Assign(bmp);
}
__finally {
delete bmp;
}
> import the BMP in my TImage component
No. You operate on a separate TBitmap. You do not put the bitmap into the
TImage while you are drawing on it.
Gambit
Re: How to draw into a jpeg image
Author: Remy Lebeau (TeamB)
Date: Wed, 02 Jun 2004 18:00
Date: Wed, 02 Jun 2004 18:00
18 lines
1708 bytes
1708 bytes
"Giuliano" <gcardinali@remove.adhoc.net> wrote in message
news:7s5rb05gt1theg28fcvkmrgd4jla7cvno1@4ax.com...
> // oppure... assegna il JPEG appena creato ad un componente TImage
> Image1->Picture->Bitmap->Assign( JPG.get() );
You can (and should) store the JPG into the TImage directly:
Image1->Picture->Graphic = JPG.get();
TJPEGImage derives from TGraphic, and thus can be used with TPicture
directly. Internally, the Graphic property will make a copy of the source
JPG. Do not keep converting it to a bitmap. The more conversions you do,
the more quality is lost from the image since JPG is a lossy format.
Gambit
Re: How to draw into a jpeg image
Author: Giuliano
Date: Thu, 03 Jun 2004 00:06
Date: Thu, 03 Jun 2004 00:06
24 lines
1836 bytes
1836 bytes
On Wed, 2 Jun 2004 11:00:51 -0700, "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com> wrote: > >"Giuliano" <gcardinali@remove.adhoc.net> wrote in message >news:7s5rb05gt1theg28fcvkmrgd4jla7cvno1@4ax.com... > >> // oppure... assegna il JPEG appena creato ad un componente TImage >> Image1->Picture->Bitmap->Assign( JPG.get() ); > >You can (and should) store the JPG into the TImage directly: > > Image1->Picture->Graphic = JPG.get(); > >TJPEGImage derives from TGraphic, and thus can be used with TPicture >directly. Internally, the Graphic property will make a copy of the source >JPG. Do not keep converting it to a bitmap. The more conversions you do, >the more quality is lost from the image since JPG is a lossy format. > > >Gambit > Have you tried it?
Re: How to draw into a jpeg image
Author: Remy Lebeau (TeamB)
Date: Thu, 03 Jun 2004 00:25
Date: Thu, 03 Jun 2004 00:25
10 lines
1247 bytes
1247 bytes
"Giuliano" <gcardinali@remove.adhoc.net> wrote in message news:e0rsb05dp8hb4tj7lmotgrpe1l18a9kt6v@4ax.com... > ??? And your actual question is ... ? Gambit
Re: How to draw into a jpeg image
Author: Giuliano
Date: Thu, 03 Jun 2004 07:21
Date: Thu, 03 Jun 2004 07:21
19 lines
1457 bytes
1457 bytes
On Wed, 2 Jun 2004 17:25:55 -0700, "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com> wrote: > >"Giuliano" <gcardinali@remove.adhoc.net> wrote in message >news:e0rsb05dp8hb4tj7lmotgrpe1l18a9kt6v@4ax.com... > >> ??? > >And your actual question is ... ? > > >Gambit > As far as I know, the JPGE algorithm is lossy when it encodes not when it decodes. Giuliano
Re: How to draw into a jpeg image
Author: Giuliano
Date: Thu, 03 Jun 2004 09:18
Date: Thu, 03 Jun 2004 09:18
41 lines
2209 bytes
2209 bytes
On Thu, 3 Jun 2004 02:06:01 -0700, "Remy Lebeau \(TeamB\)"
<gambit47.no.spam@no.spam.yahoo.com> wrote:
>
>"Giuliano" <gcardinali@remove.adhoc.net> wrote in message
>news:kcktb098ube80ktpgcev2nmccevjlui7jc@4ax.com...
>
>> As far as I know, the JPGE algorithm is lossy
>> when it encodes not when it decodes.
>
>What do you think is happening when you assign a BMP to a JPG? It encodes
>it. You assign a bitmap to a JPG, you lose a little. Then you decode the
>reduced JPG to a bitmap and then encode it back to a JPG, thus losing a
>little again. See the pattern?
>
>
>Gambit
>
What do you think is happening when you assign a JPG to a BMP?
Image1->Picture->Bitmap->Assign( JPG.get() );
It converts the JPG in a DIB (or DDB) and it's loseless because the lossy is
in the encoding operation, so doing
Image1->Picture->Bitmap->Assign( JPG.get() );
or dooing
Image1->Picture->Bitmap->Assign( JPG.get() );
or
Image1->Picture->Graphic = JPG.get();
is the same thing.
See the picture?
Giuliano
Re: How to draw into a jpeg image
Author: Giuliano
Date: Thu, 03 Jun 2004 09:25
Date: Thu, 03 Jun 2004 09:25
15 lines
1968 bytes
1968 bytes
On Thu, 3 Jun 2004 02:06:01 -0700, "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com> wrote: >What do you think is happening when you assign a BMP to a JPG? It encodes >it. You assign a bitmap to a JPG, you lose a little. Then you decode the >reduced JPG to a bitmap and then encode it back to a JPG, thus losing a >little again. See the pattern? ...moreover because, AFAIK, you can't modify the JPEG directly in TImage, yuo have to pass for a DIB then converting it into a JPEG again if you want a JPEG back. So this operation is lossy. Again, the GDI is not capable to display a JPEG directly becuase it should need to convert the JPEG into a DIB (or DDB) before to display it. So, in the VCL layer, the conversion from JPG to DIB od DDB has to happen, wich is loseless beacuse it's a decoding.
Re: How to draw into a jpeg image
Author: Remy Lebeau (TeamB)
Date: Thu, 03 Jun 2004 17:10
Date: Thu, 03 Jun 2004 17:10
13 lines
1592 bytes
1592 bytes
"Giuliano" <gcardinali@remove_adhoc.net> wrote in message
news:40beec16.149288578@newsgroups.borland.com...
> It converts the JPG in a DIB (or DDB) and it's loseless
> because the lossy is in the encoding operation
Which is what happens when you assign the bitmap *back* to the JPG after
modifying it:
JPG->Assign(TheBitmap);
Gambit
Re: How to draw into a jpeg image
Author: Remy Lebeau (TeamB)
Date: Thu, 03 Jun 2004 17:12
Date: Thu, 03 Jun 2004 17:12
11 lines
1618 bytes
1618 bytes
"Giuliano" <gcardinali@remove_adhoc.net> wrote in message news:40bfecf8.149514656@newsgroups.borland.com... > ...moreover because, AFAIK, you can't modify the JPEG directly > in TImage, yuo have to pass for a DIB then converting it into a > JPEG again if you want a JPEG back. So this operation is lossy. Which is what I said 2 days ago in my original reply. Gambit
Re: How to draw into a jpeg image
Author: Giuliano
Date: Thu, 03 Jun 2004 23:37
Date: Thu, 03 Jun 2004 23:37
24 lines
1934 bytes
1934 bytes
On Thu, 3 Jun 2004 10:10:55 -0700, "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com> wrote: > >"Giuliano" <gcardinali@remove_adhoc.net> wrote in message >news:40beec16.149288578@newsgroups.borland.com... > >> It converts the JPG in a DIB (or DDB) and it's loseless >> because the lossy is in the encoding operation > >Which is what happens when you assign the bitmap *back* to the JPG after >modifying it: > > JPG->Assign(TheBitmap); > > >Gambit > Really? What if I would like to create a modified JPEG from another JPEG? This how my original snipped was conceived. Has this so much annoyed you? For the original poster this should be a starting point.
Re: How to draw into a jpeg image
Author: Giuliano
Date: Thu, 03 Jun 2004 23:39
Date: Thu, 03 Jun 2004 23:39
18 lines
1792 bytes
1792 bytes
On Thu, 3 Jun 2004 10:12:22 -0700, "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com> wrote: > >"Giuliano" <gcardinali@remove_adhoc.net> wrote in message >news:40bfecf8.149514656@newsgroups.borland.com... > >> ...moreover because, AFAIK, you can't modify the JPEG directly >> in TImage, yuo have to pass for a DIB then converting it into a >> JPEG again if you want a JPEG back. So this operation is lossy. > >Which is what I said 2 days ago in my original reply. > > >Gambit > And what it has added your useless comment to my reply?
Re: How to draw into a jpeg image
Author: Remy Lebeau (TeamB)
Date: Fri, 04 Jun 2004 02:48
Date: Fri, 04 Jun 2004 02:48
18 lines
1837 bytes
1837 bytes
"Giuliano" <gcardinali@remove.adhoc.net> wrote in message news:nucvb0lqi70qn3vakejidh82d0htl0cdft@4ax.com... > Really? > What if I would like to create a modified JPEG from another JPEG? Without seeing TJPEGImage's actual source code (which Borland does not distribute) I would image that it is able to do a direct copy without any lose of data. > This how my original snipped was conceived. Your original code was assigning the JPG to a BMP and then assigning the BMP back to the JPG again. Gambit
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads