Does anybody know which is the fastest way to work (I want to have the RGB
value of one Pixel) with Bitmaps (352*288)? Do I have to use a TBitmap or a
TImage (which is faster?). Or is there any other possibility that is still
faster than both?
By the way, how can i figure out the three RGB values that has one Pixel
(because I only get one value - I can´t work with it).
OK Thank you in advance,
Stefan Hinterstoißer
Stevee,
I recommend you look into the ScanLine property of TBitmap. I have
some examples that use ScanLine to do some bitmap manipulations. You can
download them here:
http://norfolkgraphics.com/bcb.html
The examples show setting and reading the individual red, green, and
blue values.
As far as TImage or TBitmap being faster, I don't know that there's
going to be much of a detectable difference for most things. If you are
going to be changing an image, it should be a little faster to do it in
an off-screen TBitmap rather than a TImage on a form, since you don't
have to worry about the cycles used by the TImage redrawing itself as
changes are made.
Hope this helps,
Alan McIntyre
al...@norfolkgraphics.com
http://norfolkgrapics.com
Learn how to improve your
search engine ranking at:
http://www.webposition.com/d2.pl?r=GA0-5556
If you want to use BCB object to handle your bitmap,
TBitmap is the object you need.
In TImage, there actually is a TBitmap object inside.
If you want to manipulate lots of pixels in the bitmap,
perhaps you would like to use the scanline property of TBitmap.
However, you can also use the Pixels property of the Canvas
of TBitmap.
With Pixels[X][Y] you get a TColor value (4 bytes),
which represents the RGB value of the pixel, as well as some
palette information (see the online help for detail).
In the simplest case, the R value of the pixel is
myBitmap->Canvas->Pixels[X][Y] & clRed
and the G and B values are respectively
( myBitmap->Canvas->Pixels[X][Y] & clLime ) >> 8
and
( myBitmap->Canvas->Pixels[X][Y] & clBlue ) >> 16
For more efficient image processing operations,
you might have to look into the BitBlt API and related topics.
Good luck.
K.K.Liang
IAMS, Academia Sinica, Taiwan
Steveee <Ste...@t-online.de> schreef in berichtnieuws
89jk2c$khq$1...@news00.btx.dtag.de...
> Hi out there!
>
> Does anybody know which is the fastest way to work (I want to have the RGB
> value of one Pixel) with Bitmaps (352*288)?
Hmm, for one pixel only have a look at the Pixel property of a TBitmap, but
since I presume you actually want to do something to more than one pixel on
a pixel by pixel basis have a look at the ScanLine property.
You have to cast it's return to a type corresponding to the PixelFormat
property of the used bitmap. So if you want to address a scanline for a
PixelFormat of pf24bit for instance you do RGBTRIPLE *line =
(RGBTRIPLE*)Bitmap->ScanLine[index];
> Do I have to use a TBitmap or a TImage (which is faster?).
Well, it depends. If you plan to do a lot of bit fiddling<g> it's probably
faster to do that in a TBitmap in memory and when you're ready copy the
result to the TImage.
> Or is there any other possibility that is still faster than both?
Probably, but then you get in the realms of asm code...
> By the way, how can i figure out the three RGB values that has one Pixel
> (because I only get one value - I can´t work with it).
See RGBTRIPLE, RGBQUAD in the WinApi online help for pf24bit and pf32bit
respectively. For pf15bit and pf16bit you can use a WORD (unsigned short in
bcb) to get them from a ScanLine, but for splitting them up you need to roll
your own struct afaik. Something like:
#pragma push(1)
struct RGB15 {
WORD r:5;
WORD g:5;
WORD b:5;
WORD unused:1;
};
#pragma pop
> OK Thank you in advance,
Hope this helped a little...;-))
> Stefan Hinterstoißer
--
Greetings from rainy Amsterdam
Jan
email: bij...@worldonline.nl
http://home.worldonline.nl/~bijster
I do a lot of work with proprietory medical images and found that the
absolute best is to locate a copy of ImageMod - A Better TImage and
TBitmap for Borland C++ Builder 3!
by Timon Marmex Trzepacz - Working Designs - Codeware
This gives one direct access to the bit array and palette of the bitmap.
Can't remember where I found it but I recall it appearing in many of the
archives (Tories, etc.). If not, I think I could dig up the files.
I believe there was also a version for BCB1.
Direct access to the bits beats the heck out of using scanline for speed, as
a pointer to any array can then be used.
Antony T. Heisler
Meditherm Clinical Infrared
ahei...@intergate.bc.ca
> Does anybody know which is the fastest way to work (I want to have the RGB
> value of one Pixel) with Bitmaps (352*288)? Do I have to use a TBitmap or
a
> TImage (which is faster?). Or is there any other possibility that is still
> faster than both?
> By the way, how can i figure out the three RGB values that has one Pixel
> (because I only get one value - I can´t work with it).
> OK Thank you in advance,
>
> Stefan Hinterstoißer
>
>
http://www.torry.ru/vcl/graphics/imagemod.zip
Thanks for the tip, Antony
Larry
"Antony T. Heisler" <ahei...@intergate.bc.ca> wrote in message
news:8af7bv$lh...@bornews.borland.com...
To work with 24 bpp bitmaps I create a BGR struct
struct BGR {Byte alpha; Byte blue; Byte green; Byte red;}; (ABGR)
Then create a 2d array of BGR the height and width of your bitmap
BGR[352][288];
Then I convert my bitmap into a 2d array of BGR using the following
for(int y = 0; y < bitmap->Height; y++)
for(int x = 0; x < bitmap->Width;x++)
BGRColor(bitmap->Canvas->Pixels[y][x],BGR[y][x]);
where BGRColor is
BGRColor(TColor color,BGR &bgr)
{
DWORD ColorHex = ColorToRGB(color);
bgr.red = (BYTE)(ColorHex & 0xFF);
bgr.green = (BYTE)((ColorHex >> 8) & 0xFF);
bgr.blue = (BYTE)(ColorHex >> 16);
}
Then to process pixels in BGR
BGR* BGRptr;
for(int y = 0; y < bitmap->Height; y++){
BGRptr = (BGR*) bitmap->ScanLine[y];
for(int x = 0; x < bitmap->Width;x++){
BGRptr[x].blue = some operation;
BGRptr[x].green = some operation;
BGRptr[x].red = some operation;
}
}
Any comments welcome.
Terry Stafford
On Sat, 11 Mar 2000 20:56:07 -0800, "Antony T. Heisler"
<ahei...@intergate.bc.ca> wrotf: