Board index » cppbuilder » How show pgm format in a Tpicture?

How show pgm format in a Tpicture?

My question is very simple:
I need to show a matrix of one image with size of pixel=1byte, and in
gray scale.
The easer format to do this is the pgm but I can`t show in TPicture.
Can I hep me somebody?.
thaks.    :)
 

Re:How show pgm format in a Tpicture?


Hi Stakas,

Quote
> I need to show a matrix of one image with size of pixel=1byte, and in
> gray scale.

You can use the TBitmap::Scanline property to display a simple array of pixels.
If each pixel represents one byte, then set the PixelFormat property to pf8bit.
To have a grayscale image, use the SetDIBColorTable API function.  Once all of
this is set up, you can simply transfer your matrix values to the bitmap bits
via the ScanLine property.  Here's some code to get you started...

std::auto_ptr<Graphics::TBitmap> Bitmap(new Graphics::TBitmap());
    Bitmap->Width = Image1->Width;
    Bitmap->Height = Image1->Height;
    Bitmap->HandleType = bmDIB;
    Bitmap->PixelFormat = pf8bit;

    RGBQUAD rgbQ[256];
    for (int index = 0; index < 256; ++index)
    {
        rgbQ[index].rgbRed = static_cast<unsigned char>(index);
        rgbQ[index].rgbBlue = static_cast<unsigned char>(index);
        rgbQ[index].rgbGreen = static_cast<unsigned char>(index);
        rgbQ[index].rgbReserved = 0;                        
    }
    SetDIBColorTable(Bitmap->Canvas->Handle, 0, 256, rgbQ);

    int height = Bitmap->Height;
    int width = Bitmap->Width;

    for (int y = 0; y < height; ++y)
    {
        unsigned char *bits =
            static_cast<unsigned char *>(Bitmap->ScanLine[y]);    
        for (int x = 0; x < width; ++x)
        {
            bits[x] = 128;  // use your matrix values instead
        }
    }

    Image1->Picture->Assign(Bitmap.get());

Good luck!

--
Damon Chandler
http://bcbcaq.freeservers.com

Re:How show pgm format in a Tpicture?


#include <memory>

Quote
> Good luck!

--
Damon Chandler
http://bcbcaq.freeservers.com

Other Threads