Home Articles Books Downloads FAQs Tips

Q: Display JPEG images


Answer

Use the class TJPEGImage to load the JPEG, and then use the Assign method to draw the JPEG onto a regular TImage. Here is a code example that demonstrates how.

#include <jpeg.hpp>

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    // Create a TJPEGImage, and tell it to load the file conf99.jpg
    TJPEGImage *JImage = new TJPEGImage;
    JImage->LoadFromFile("conf99.jpg");

    // Now that we have a TJEGImage, we can use Assign to
    // copy that image into a TImage.
    Image1->Width  = JImage->Width;
    Image1->Height = JImage->Height;
    Image1->Picture->Assign(JImage);

    delete JImage;
}

Figure 1 shows the program in action. The image is a picture of me and my son playing games during the DirectX madness event at Borcon 99. The picture was taken by Danny Thorpe, and its part of his photo gallery on the community website. Fortunately for you, Danny took a picture of my best side.



Figure 1. Displaying JPEG files from a BCB program


Downloads for this FAQ
faq89.zip Source code for this FAQ.


Copyright © 1997-2000 by Harold Howe.
All rights reserved.