Board index » cppbuilder » TImage and TJPEGimage...

TImage and TJPEGimage...


2005-04-30 07:45:31 PM
cppbuilder109
the following code:
jp->Assign(Image1->Picture->Graphic);
jp->Compress();
Image2->Picture->Assign(jp);
jp is a TJPEGImage that is global.
the problem is that image2 displays exactly
the same image as Image1. whereas in the
following code that does not happen:
jp->Assign(Image1->Picture->Graphic);
jp->Compress();
jp->SaveToFile("1.jpg");
Image2->Picture->LoadFromFile("1.jpg");
why isn't there a LoadFromStream method in TPicture????
Is There Something i am doing wrong?
Just Something else the TJPEGImage's GrayScale Property is set
to true and this is how i know if the code will work.
Here is what i do inside the contructor of Form1:
jp=new TJPEGImage();
jp->GrayScale=true;
jp->CompressionQuality=50;
 
 

Re:TImage and TJPEGimage...

"qyte" < XXXX@XXXXX.COM >wrote in message
Quote
why isn't there a LoadFromStream method in TPicture????
A LoadFromStream() implementation would be dependant on the specific format
being loaded, but TPicture is too generic to know which format is being
loaded prior to actually loading the data, so it wouldn't know which
TGraphic class should handle the loading. The only reason LoadFromFile()
can exist in TPicture is because the appropriate TGraphic type can be
determine based on the file's extension before the file is actually opened.
The same cannot be said for loading a TStream since there is currently no
way for TPicture to determine which specific image
Gambit
 

Re:TImage and TJPEGimage...

Remy Lebeau (TeamB) wrote:
Quote
>why isn't there a LoadFromStream method in TPicture????


A LoadFromStream() implementation would be dependant on the specific format
being loaded, but TPicture is too generic to know which format is being
loaded prior to actually loading the data, so it wouldn't know which
TGraphic class should handle the loading. The only reason LoadFromFile()
can exist in TPicture is because the appropriate TGraphic type can be
determine based on the file's extension before the file is actually opened.
The same cannot be said for loading a TStream since there is currently no
way for TPicture to determine which specific image


Gambit


OK with that. can you suggest a way of loading a TJPEGImage there
and not the bitmap from Image1? Is There something wrong with
my code?
 

{smallsort}

Re:TImage and TJPEGimage...

qyte wrote:
Quote
the following code:

jp->Assign(Image1->Picture->Graphic);
jp->Compress();
Image2->Picture->Assign(jp);

jp is a TJPEGImage that is global.
the problem is that image2 displays exactly
the same image as Image1.
Then we agree: the thing is not perfect.
I had to do this to make it work:
jp->Assign(Image1->Picture->Graphic);
jp->JPEGNeeded();
jp->Grayscale = true; // again!
jp->DIBNeeded();
Image2->Picture->Assign(jp);
What exactly is it that you need to do?
 

Re:TImage and TJPEGimage...

Fishface wrote:
Quote
qyte wrote:


>the following code:
>
>jp->Assign(Image1->Picture->Graphic);
>jp->Compress();
>Image2->Picture->Assign(jp);
>
>jp is a TJPEGImage that is global.
>the problem is that image2 displays exactly
>the same image as Image1.


Then we agree: the thing is not perfect.
I had to do this to make it work:

jp->Assign(Image1->Picture->Graphic);
jp->JPEGNeeded();
jp->Grayscale = true; // again!
jp->DIBNeeded();
Image2->Picture->Assign(jp);


What exactly is it that you need to do?


i will try it and let you know.
i am sending jpeg images through a server app
and i have a trackbar so i can change the quality.
i have a TImage inside the TabSheet of the Server and another
in the Camera tabsheet. and i want to know how the images look like.
the problem is that the two images show the same thing.
 

Re:TImage and TJPEGimage...

Fishface wrote:
Quote
jp->Assign(Image1->Picture->Graphic);
jp->JPEGNeeded();
jp->Grayscale = true; // again!
jp->DIBNeeded();
Image2->Picture->Assign(jp);

Unfortunately it does not work.
In fact it works vise versa. i mean
that when GrayScale is true the picture is in
full colour. and vise versa.
Apart from that neither does the CompressionQuality.
I aplly it just after GrayScale and it does Nothing.
I cannot see what exactly i am doing wrong. It
Should work in the first place Shouldn't it?
 

Re:TImage and TJPEGimage...

qyte wrote:
Quote
Unfortunately it does not work.
In fact it works vise versa. i mean
that when GrayScale is true the picture is in
full colour. and vise versa.
Yes, very strange. I hadn't created the JPEGImage in the constructor,
nor had I set Grayscale to true prior to executing that code.
Quote
Apart from that neither does the CompressionQuality.
I aplly it just after GrayScale and it does Nothing.
I cannot see what exactly i am doing wrong. It
Should work in the first place Shouldn't it?\
I think it should. I would suggest not setting the Greyscale and
CompressionQuality in the constructor and doing it in this order.
This thing seems to be very fussy!
jp->Assign(Image1->Picture->Graphic);
jp->CompressionQuality = 50;
jp->JPEGNeeded();
jp->Grayscale = true;
jp->SaveToFile("M://test.jpg");
jp->DIBNeeded();
Image2->Picture->Assign(jp);
Setting the CompressionQuality here resulted in a 43KB file versus
125KB without.
 

Re:TImage and TJPEGimage...

Fishface wrote:
Quote

Yes, very strange. I hadn't created the JPEGImage in the constructor,
nor had I set Grayscale to true prior to executing that code.



jp->Assign(Image1->Picture->Graphic);
jp->CompressionQuality = 50;
jp->JPEGNeeded();
jp->Grayscale = true;
jp->SaveToFile("M://test.jpg");
jp->DIBNeeded();
Image2->Picture->Assign(jp);


i found another way that works.
Even though i don't know why.
TMemoryStream jp_tmp=new TMemoryStream;
jp->Assign(Image1->Picture->Graphic);
jp_tmp->Position=0;
jp->SaveToStream(jp_tmp);
jp_tmp->Position=0;
jp->LoadFromStream(jp_tmp);
Image2->Picture->Assign(jp);
then Image2 displays the Jpeg Image exactly as it should.