 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
José Guest
|
Posted: Thu Apr 20, 2006 8:03 pm Post subject: Showing pictures quickly |
|
|
Dear friends
I try to display a slide show using TImage->Picture->LoadFromFile()
This procedure, simple as it seems, is rather slow.
I tried the following solutions:
1. Using two TImages. Loading the 2nd one while the first is
displayed, and then toggling the Visible property.
This made no difference.
I presume that an image is not loaded until it is made visible. So I
tried this:
2. Same as above, but the Visible property remains true. An image is
made invisible by setting its Top property so that it is beyond the
edge of the screen.
This made no difference either.
Any help?
--
José |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Thu Apr 20, 2006 11:03 pm Post subject: Re: Showing pictures quickly |
|
|
"José" <jose (AT) 127 (DOT) 0.0.1> wrote in message
news:kgpf42dr6rnf7brcbooin2pmsma45l67uq (AT) 4ax (DOT) com...
| Quote: | This procedure, simple as it seems, is rather slow.
|
That depends on the kinds of images you are trying to display, and how large
they are.
| Quote: | Using two TImages. Loading the 2nd one while the first is
displayed, and then toggling the Visible property.
This made no difference.
|
Please show your actual code. When exactly are you loading the next file?
| Quote: | I presume that an image is not loaded until it is made visible.
|
Not true. The image data is completely in memory when LoadFromFile() exits.
Gambit |
|
| Back to top |
|
 |
Bruce Larrabee Guest
|
Posted: Fri Apr 21, 2006 4:03 am Post subject: Re: Showing pictures quickly |
|
|
Hello guys,
This is code I use in my slideshow program. It can sometimes load
rather large hires images in under 0.5 seconds. (I was impressed... ;)
You can download the app a check it out if you're curious...
http://www.westbrookent.com/SlideShowSetup2.0.exe
/~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void __fastcall TMain_Window::LoadImage( void)
{
// load image...
char *ext = "XXXXXXXX";
ext = get_ext( ext, file_list->Strings[current_image].c_str());
if(ext == NULL)
{
return;
}
ImageWindow->Top = 0;
ImageWindow->Left = 0;
ImageWindow->Height = 1024;
ImageWindow->Width = 1280;
if(strcmp( ext, "jpg") == 0)
{
// load a jpg...
jpeg_image = new TJPEGImage;
jpeg_image->Scale = jsFullSize;
jpeg_image->Performance = jpBestQuality;
jpeg_image->PixelFormat = jf24Bit;
jpeg_image->ProgressiveDisplay = false;
jpeg_image->Smoothing = false;
jpeg_image->Grayscale = false;
try
{
jpeg_image->LoadFromFile( file_list->Strings[current_image].c_str());
}
catch(...)
{
if(FixDirectoryPath.c_str() != "")
{
// if there IS a Fix directory selected...
AnsiString file;
file = StripFileName( file_list->Strings[current_image].c_str());
strcpy( buffer, FixDirectoryPath.c_str());
strcat( buffer, "\\");
strcat( buffer, file.c_str());
AnsiString new_path( buffer);
MoveFile( new_path, file_list->Strings[current_image]);
RemoveCurrentFileFromList();
}
else
{
// if there IS NOT a fix directory selected...
RemoveCurrentFileFromList();
}
delete jpeg_image;
return;
}
ImageWindow->Picture->Assign(jpeg_image);
TextBuffer = file_list->Strings[current_image];
FileNameLabel->Caption = file_list->Strings[current_image];
image_height = jpeg_image->Height;
image_width = jpeg_image->Width;
delete jpeg_image;
}
}
/~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Hope that helps,
Bruce Larrabee |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Fri Apr 21, 2006 6:03 am Post subject: Re: Showing pictures quickly |
|
|
"Bruce Larrabee" <bruce_l (AT) westbrookent (DOT) com> wrote in message
news:444856e2 (AT) newsgroups (DOT) borland.com...
| Quote: | This is code I use in my slideshow program.
|
The code is converting AnsiString values to char* and then passing those to
methods that expected AnsiString, so you have the overhead of unnecessary
memory allocations and string conversions. And you are accessing the string
list over and over, so you have repeated range checking as well.
Try this code instead:
#include <memory>
void __fastcall TMain_Window::LoadImage(void)
{
AnsiString FileName = file_list->Strings[current_image];
AnsiString ext = ExtractFileExt(FileName);
if( !AnsiSameText(ext, ".jpg") )
return;
std::auto_ptr<TJPEGImage> jpeg_image(new TJPEGImage);
try
{
jpeg_image->Scale = jsFullSize;
jpeg_image->Performance = jpBestQuality;
jpeg_image->PixelFormat = jf24Bit;
jpeg_image->ProgressiveDisplay = false;
jpeg_image->Smoothing = false;
jpeg_image->Grayscale = false;
jpeg_image->LoadFromFile(FileName);
}
catch(const Exception &)
{
if( !FixDirectoryPath.IsEmpty() )
{
wsprintf(buffer, "%s\\%s", FixDirectoryPath.c_str(),
ExtractFileName(FileName).c_str());
::MoveFile(buffer, FileName.c_str());
}
RemoveCurrentFileFromList();
return;
}
try
{
ImageWindow->SetBounds(0, 0, 1280, 1024);
ImageWindow->Picture->Assign(jpeg_image.get());
}
catch(const Exception &)
{
// do something ...
return;
}
TextBuffer = FileName;
FileNameLabel->Caption = FileName;
image_height = jpeg_image->Height;
image_width = jpeg_image->Width;
}
Gambit |
|
| Back to top |
|
 |
José Guest
|
Posted: Fri Apr 21, 2006 7:03 am Post subject: Re: Showing pictures quickly |
|
|
On Thu, 20 Apr 2006 15:16:40 -0700, "Remy Lebeau \(TeamB\)"
<no.spam (AT) no (DOT) spam.com> wrote in borland.public.cppbuilder.graphics:
| Quote: | That depends on the kinds of images you are trying to display, and how large
they are.
|
500 kB, 1280x1024
| Quote: | Using two TImages. Loading the 2nd one while the first is
displayed, and then toggling the Visible property.
This made no difference.
Please show your actual code. When exactly are you loading the next file?
|
Of course I load it immediately after displaying the previous picture.
It then sits there waiting for the TTimer. When the TTimer fires, the
other picture is displayed and the next file loaded.
| Quote: | I presume that an image is not loaded until it is made visible.
Not true. The image data is completely in memory when LoadFromFile() exits.
|
In that case it appears that the delay is in the display itself.
It mat be interesting to know that there are two monitors, and that
two simultaneous pictures are displayed. This means that there are
four TImage objects: two for display and two to load the next picture.
--
José |
|
| Back to top |
|
 |
Bruce Larrabee Guest
|
Posted: Fri Apr 21, 2006 8:03 am Post subject: Re: Showing pictures quickly |
|
|
Hey Remy,
Your tips are most edifying (and appreciated... :)
I must post more code...
Hope ~some~ of my posts actually help someone... B)
(Ok, I know some do...)
Thanks,
Bruce Larrabee |
|
| Back to top |
|
 |
Thorsten Kettner Guest
|
Posted: Mon Apr 24, 2006 8:03 am Post subject: Re: Showing pictures quickly |
|
|
José <jose (AT) 127 (DOT) 0.0.1> wrote:
| Quote: | Of course I load it immediately after displaying the previous
picture. It then sits there waiting for the TTimer. When the
TTimer fires, the other picture is displayed and the next file
loaded.
|
To check if reading the picture from file or making it visible
is the slow part, simply let it beep after LoadFromFile.
Your technique reading the picture into a second TImage and
toggle visibility should be fast enough. You might want to check
hd speed (fragmentation, hard disk errors) and available memory. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|