PDA

View Full Version : Help - graphics



Shadowbird
28-07-2003, 04:24 PM
I know I will be arrested for murder after this post because most of you will probably laugh to your death over the "problem" I have stated below, but what the hell - I still want it solved.

I've been poking around with Delph for some time now, but when it comes to graphics (and I don't mean DirectX, I mean TImage and TBitmap) I'm a "doodoo-beaten-with-a-stupid-stick". The deal is this:

I have: x*y sized array of indexes (bytes).
What I need: To display a graphical image (bmp preferably, but it doesn't matter) using each array element as a color index for the 256 color palette.

In other words, I need explicit (remember, I'm a doo-doo :)) instructions on how to Create/Load standart 256 color palette in a way that I can access it's colors by indexes, and then draw (fast) these indexes onto a TImage component (i've been told to use scanlines, but to tell you the truth, I've got no idea what are those - that is, how to use them). Hey, stop laughing! :)

So - any help?

tux
28-07-2003, 04:51 PM
um, to draw an image to a TImage from TBitmap do this

Image1.Picture.Bitmap := Bitmap;

or

Image1.Canvas.Draw(0, 0, Bitmap);

Shadowbird
28-07-2003, 04:58 PM
OK, I'll try to explain in yet another words:

I don't have a bitmap. I have an array of indexes, each index indicating a specific color in 256 color palette. I need to know how can I get the colors these indexes point to, and how to draw them on a TImage component.

wilbur989
28-07-2003, 11:49 PM
If I understand your question correctly, you want to draw a bitmap to a TImage but you are using you own format in the form of this array of colors? If this is what you are saying then what you would do is something like this.

Procedure DrawImage;
var
X, Y: Integer;

begin
for X := 0 to {whatever the high end of the X axis is} do
for Y := 0 to {whatever the high end of the Y axis is} do
Image1.Canvas.Pixels[x, y] := {the color value in hex i.e '$ff00ff};
end;

The only thing you need to make sure of is that you set the bounds of your TImage before you draw to the canvas. If this still is not what you are looking for lemme know.

-Jeremy

Avatar
29-07-2003, 12:24 AM
Hi !

I guess that wilbur989 is right ... Anyway, if you want(later) to work on huge images, and have good efficiency, I advise you not to use Pixels but scanlines ...

Anyway, you should take a look at this link :

http://www.efg2.com/Lab/

You should find what you're looking for here ^^

Bye !

Avatar

Shadowbird
29-07-2003, 02:44 PM
wilbur989, you were almost right. You see, I don't have color's either! I only have indexes to them. from 0 (I believe it's black) to 255 (could be white, but I'm not sure). These indexes indicate colors in standard Windows 256-color palette. What I'm trying to find is a way to get those indexes (the canvas.pixels[x, y] part I know - but it worked real slow for me - the image size was about 120x60 pixels or so).

The color palette is array[0..255] of {color}, and I have array[0..255] of byte. Get the picture? I need access to that first array, and I can't seem to get it.

wilbur989
29-07-2003, 03:51 PM
Ok I understand now. Using the link provided by Avatar I think I found Exactly what your looking for. This will use scanlines so it may end up being a bit faster.

procedure DrawImage;
var
X, Y: Integer;
Bmp: TBitMap;
Row: pByteArray;

begin
Bmp := TBitMap.Create;
Bmp.Width := 60;
Bmp.Height := 120;
Bmp.PixelFormat := pf8bit;
for X := 0 to Bmp.Height - 1 do
begin
Row := Bmp.ScanLine[X];
For Y := 0 to Bmp.Width - 1 do
begin
Row[Y] := {Your Color index value};
end;
end;
end;

This will use the default palette. If you want to change any of the colors in the palette look at the delphi help for TBitmap.palette. It has a good example there. Also sorry if I reversed the width and height. I was not as concerned with that as I was the example.

-Jeremy

Shadowbird
30-07-2003, 07:52 AM
OK, thanx, I'll check it out A.S.A. I have the time.