Board index » cppbuilder » TImage to JPEG problem

TImage to JPEG problem


2004-09-23 12:36:00 AM
cppbuilder92
Hi,
I want to change the format of the pictures which are loaded into a TImage
component to the JPEG format and then save it in a memory stream. I used the
below code:
if(Image1->Picture->Bitmap->Empty)
PictureMemStream->SetSize(0);
else
{ //JPEGImage is a global TJPEGImage
JPEGImage->Assign(Image1->Picture->Bitmap);
JPEGImage->SaveToStream(PictureMemStream);
}
But the "Image1->Picture->Bitmap->Empty" is usually empty even when I loaded
a picture. How can I find that the picture is empty or not? Is there any
better way to change the format?
Thank you,
Mehrdad
 
 

Re:TImage to JPEG problem

But when I change it to " JPEGImage->Assign(Image1->Picture->Graphic);" I
get this error message:
-------------------------------------
Assertion failed: !"bogus context in _ExceptionHandler()", file xx.cpp, line
3071
-------------------------------------
What can I do?
Mehrdad
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"M. Noroozi Eghbali" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>if(Image1->Picture->Bitmap->Empty)

Change that to this instead:

if(Image1->Picture->Bitmap->Empty)

if(Image1->Picture->Graphic->Empty)

>JPEGImage->Assign(Image1->Picture->Bitmap);

Change that to this:

JPEGImage->Assign(Image1->Picture->Graphic);

>But the "Image1->Picture->Bitmap->Empty" is usually
>empty even when I loaded a picture.

Did you load a bitmap into the TImage to begin with? If not, then as soon
as you access the Bitmap property, the original image is lost and replaced
with an empty bitmap. TPicture does not convert image formats from one to
another. If you load one format and then try to access a different
format,
the original is destroyed.

If you are not doing so already, have you considered storing an actual JPG
into the TImage as-is? Then you could just save the data without using a
global TJPEGImage at all:

if( Image1->Picture->Graphic->Empty )
PictureMemStream->Size = 0;
else
Image1->Picture->Graphic->SaveToStream(PictureMemStream);


Gambit


 

Re:TImage to JPEG problem

Maybe something like this / untested /:
bool IsImageEmpty( TImage *I )
{
if ( ( I->Picture->Graphic ) && ( !I->Picture->Graphic->Empty ) )
return ( false );
return ( true );
}
Best regards,
Vladimir Stefanovic
M. Noroozi Eghbali < XXXX@XXXXX.COM >wrote in message
Quote
Hi,

I want to change the format of the pictures which are loaded into a
TImage
component to the JPEG format and then save it in a memory stream. I
used the
below code:

if(Image1->Picture->Bitmap->Empty)
PictureMemStream->SetSize(0);
else
{ file://JPEGImage is a global TJPEGImage
JPEGImage->Assign(Image1->Picture->Bitmap);
JPEGImage->SaveToStream(PictureMemStream);
}

But the "Image1->Picture->Bitmap->Empty" is usually empty even when
I loaded
a picture. How can I find that the picture is empty or not? Is there
any
better way to change the format?

Thank you,
Mehrdad


 

{smallsort}

Re:TImage to JPEG problem

"M. Noroozi Eghbali" < XXXX@XXXXX.COM >wrote in message
Quote
if(Image1->Picture->Bitmap->Empty)
Change that to this instead:
if(Image1->Picture->Bitmap->Empty)
if(Image1->Picture->Graphic->Empty)
Quote
JPEGImage->Assign(Image1->Picture->Bitmap);
Change that to this:
JPEGImage->Assign(Image1->Picture->Graphic);
Quote
But the "Image1->Picture->Bitmap->Empty" is usually
empty even when I loaded a picture.
Did you load a bitmap into the TImage to begin with? If not, then as soon
as you access the Bitmap property, the original image is lost and replaced
with an empty bitmap. TPicture does not convert image formats from one to
another. If you load one format and then try to access a different format,
the original is destroyed.
If you are not doing so already, have you considered storing an actual JPG
into the TImage as-is? Then you could just save the data without using a
global TJPEGImage at all:
if( Image1->Picture->Graphic->Empty )
PictureMemStream->Size = 0;
else
Image1->Picture->Graphic->SaveToStream(PictureMemStream);
Gambit
 

Re:TImage to JPEG problem

"M. Noroozi Eghbali" < XXXX@XXXXX.COM >wrote in message
Quote
What can I do?
Did you try the other thing I suggested? Getting rid of the global
TJPEGImage altogether and just save the TImage Graphic directly.
Gambit
 

Re:TImage to JPEG problem

Thank you Remy. It was good suggestion and worked.
Mehrdad
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"M. Noroozi Eghbali" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>What can I do?

Did you try the other thing I suggested? Getting rid of the global
TJPEGImage altogether and just save the TImage Graphic directly.


Gambit