PDA

View Full Version : Custom graphic to TImage



M109uk
21-10-2003, 01:31 PM
Hi all,

My engine uses its own braphic format which is converted from a 24bit uncompressed TGA file, my problem is that in my editor i would like to be able to view the image using a TImage component. I have tried to use the scanline in TBitmap but im just getting a blank image :?

Thanx for any help :D

M109uk
24-10-2003, 03:08 AM
No worries,

I have finally managed to figure it out 8)

cairnswm
24-10-2003, 05:31 AM
So let us know the answer. On this site if you dont get an answer to a query it is usually because nobody knows - so if you worked it out please post us an answer.

Alimonster
24-10-2003, 08:05 AM
In this case, he didn't get an answer because this question slipped past me. :roll: Yeesh, you tune out for one minute and you miss an answerable question!

The way to do it here would be to use scanline like this (assumes the memory for the tga is continuous and that the pixels for the tga are stored as "array of byte" -- adjust for sizing appropriately)

type
TPixelArray = array[0..(MaxInt div SizeOf(TRGBTriple)) - 1] of TRGBTriple;
PPixelArray = ^TPixelArray;
var
Bmp: TBitmap;
ThisLine: PPixelArray;
y: Integer;
Offset: Integer;
begin
Bmp := TBitmap.Create;
try
Bmp.PixelFormat := pf24Bit;
Bmp.Width := MyTga.Width;
Bmp.Height := MyTga.Height;

offset := 0;

for y := 0 to Bmp.Height - 1 do
begin
ThisLine := Bmp.Scanline[y];
Move(MyTga.Pixels[offset], ThisLine^[0], Bmp.Width * SizeOf(TRGBTriple));
Inc(Offset, Bmp.Width * SizeOf(TRGBTriple));
end;

// and make sure the TImage knows about the change
Image1.Picture.Bitmap.Assign(Bmp);
finally
Bmp.Free;
end;
end;

M109uk
24-10-2003, 05:22 PM
lol sorry Alimonster, but i tried that method before and kept trying to get it to work but i just kept getting a blank image with that. In the end i used the following code ::


function TcxTexture.Bitmap: TBitmap;
var
i,j,d: Integer;
Row: pRGBTripleArray;
Bmp: TBitmap;
begin
Bmp := TBitmap.Create;

Bmp.PixelFormat := pf24bit;
Bmp.Width := fWidth;
Bmp.Height := fHeight;

d := 0;

For j := 0 To fHeight-1 Do
Begin
Row := Bmp.Scanline[j];
For i := 0 To fWidth-1 Do
Begin
Row[i].rgbtRed := fData[d+2];
Row[i].rgbtGreen := fData[d+1];
Row[i].rgbtBlue := fData[d];
Inc(d, fBpp);
End;
End;

Result := Bmp;
end;


And the data was changed from PChar to Array of Byte, and its works great 8)

If any ones intrested i can post the complete source code for my texture unit?!

M109uk
29-10-2003, 10:18 PM
Im just woundering but how can i use my texture class with TPictureDialog?
I know that there's a function to register the file format, but how can i get it to read the file and display the image?

doggo18
29-10-2003, 10:26 PM
Try studying TBitmap and TIcon for 'simple' examples. The overrided stuff is prolly everything needed, and there is also a line with Register-something in the initialization section of Graphics unit.

M109uk
30-10-2003, 11:22 AM
hey thanks for the reply, i think i have got it now.

I Created a class decendant of TBitmap and then just used the routines i have to load my textures in the loadfromfile procedure and then registered the formats with TPicture in the initialization part of the source.

I havnt got around to testing it yet though..