Thread View: borland.public.cppbuilder.multimedia
5 messages
5 total messages
Started by Colin B Maharaj
Mon, 09 Aug 2004 11:28
JPEG properties
Author: Colin B Maharaj
Date: Mon, 09 Aug 2004 11:28
Date: Mon, 09 Aug 2004 11:28
43 lines
2612 bytes
2612 bytes
Hi all, is there anyway to get the dimensions of a jpeg without opening
it and loading it into a Bitmap memory block. The code snippet here
creates a wrapper for jpegs whose file names are in a string list, if I
have 30 jpegs does it mean I load all these jpegs one by one? Is there a
way I can read the header and get the dimensions? This way I do not take
up much resources?
AnsiString MakeJPEGHtmlWrapper(TStringList * L)
{
AnsiString A = "<html>\r\n<head>\r\n</head><body><br>\r\n";
A += "<";
A += "table style=\"width: 100%; text-align: left;\"";
A += "border=\"0\"";
A += "cellpadding=\"2\"";
A += "cellspacing=\"2\"";
A += "<tbody>";
TJPEGImage *jpg = new TJPEGImage;
Graphics::TBitmap *bmp = new Graphics::TBitmap;
for (int i=0; i<L->Count; i++)
{
AnsiString B = L->Strings[i];
while (B.Length() && B.Pos("\\")>0) B.Delete(1, 1);
if (FileExists(B)==true)
{
A += "\r\n<tr>\r\n";
A += " <td style=\"vertical-align: top;\"><img title=\"";
A += (AnsiString) "Image " + IntToStr(i+1) + "\"";
A += (AnsiString) "src=\"";
A += B; A += "\"";
A += (AnsiString) " alt=\"\" ";
A += (AnsiString) " style=\"";
jpg->LoadFromFile(B); // does this take up much resources??
bmp->Assign(jpg);
A += (AnsiString) "width: " + IntToStr(bmp->Width)+"px\; " +
"height: " + IntToStr(bmp->Height)+"px\; \">";
A += " </td>\r\n </tr>\r\n ";
}
}
A += " </tbody>\r\n </table>\r\n ";
A += " </body>\r\n </html>\r\n ";
delete jpg;
return A;
}
Re: JPEG properties
Author: Remy Lebeau (TeamB)
Date: Mon, 09 Aug 2004 16:56
Date: Mon, 09 Aug 2004 16:56
35 lines
1868 bytes
1868 bytes
"Colin B Maharaj" <noreply@myhost.com> wrote in message
news:41175fe0@newsgroups.borland.com...
> Hi all, is there anyway to get the dimensions of a jpeg
> without opening it and loading it into a Bitmap memory block.
TJPEGImage inherits Width and Height properties from TGraphic. You don't
need to convert to TBitmap first:
AnsiString MakeJPEGHtmlWrapper(TStringList * L)
{
//...
TJPEGImage *jpg = new TJPEGImage;
//...
jpg->LoadFromFile(B);
//..
A += ( "width: " + IntToStr(jpg->Width) + "px; height: " +
IntToStr(jpg->Height) + "px; \">" );
//...
delete jpg;
//...
}
> The code snippet here creates a wrapper for jpegs whose
> file names are in a string list, if I have 30 jpegs does it mean
> I load all these jpegs one by one?
Yes.
> Is there a way I can read the header and get the dimensions?
Not unless you open the files yourself and decode the jpeg data manually.
Gambit
Re: JPEG properties
Author: Colin B Maharaj
Date: Tue, 10 Aug 2004 02:56
Date: Tue, 10 Aug 2004 02:56
28 lines
1822 bytes
1822 bytes
Thanks Remy for your coding tips...
Remy Lebeau (TeamB) wrote:
> "Colin B Maharaj" <noreply@myhost.com> wrote in message
> news:41175fe0@newsgroups.borland.com...
>
>
>>Hi all, is there anyway to get the dimensions of a jpeg
>>without opening it and loading it into a Bitmap memory block.
>
>
> TJPEGImage inherits Width and Height properties from TGraphic. You don't
> need to convert to TBitmap first:
>
> AnsiString MakeJPEGHtmlWrapper(TStringList * L)
> {
> //...
> TJPEGImage *jpg = new TJPEGImage;
> //...
> jpg->LoadFromFile(B);
> //..
> A += ( "width: " + IntToStr(jpg->Width) + "px; height: " +
> IntToStr(jpg->Height) + "px; \">" );
> //...
> delete jpg;
> //...
> }
Re: JPEG properties
Author: Vladimir Stefanovic
Date: Tue, 10 Aug 2004 20:17
Date: Tue, 10 Aug 2004 20:17
14 lines
1347 bytes
1347 bytes
> Is there a way I can read the header and get the dimensions? In any case you have to open the file into TImage or by fopen(). Once I needed the same thing and I discovered which bytes makes Width and which Height. You can find them fast by any HEX editor. I remember that they are not at the same offset of the file, but are surrounded with the same byte pattern. I abandoned that approach when I found the TWO such patterns in one of (maybe) 100 JPG files. Best regards, Vladimir Stefanovic
Re: JPEG properties
Author: Remy Lebeau (TeamB)
Date: Tue, 10 Aug 2004 20:50
Date: Tue, 10 Aug 2004 20:50
16 lines
1495 bytes
1495 bytes
"Vladimir Stefanovic" <spam@not.needed> wrote in message news:41192d5c@newsgroups.borland.com... > In any case you have to open the file into TImage or by fopen(). > Once I needed the same thing and I discovered which bytes makes > Width and which Height. You can find them fast by any HEX editor. > I remember that they are not at the same offset of the file, but are > surrounded with the same byte pattern. You shouldn't be making assumptions on byte patterns. Go to http://www.wotsit.org and grab the specification for the JPG format. Then you don't have to make guesses at all. 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