Results 1 to 8 of 8

Thread: Custom graphic to TImage

  1. #1

    Custom graphic to TImage

    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
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  2. #2

    Custom graphic to TImage

    No worries,

    I have finally managed to figure it out
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  3. #3
    Legendary Member cairnswm's Avatar
    Join Date
    Nov 2002
    Location
    Randburg, South Africa
    Posts
    1,537

    Custom graphic to TImage

    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.
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

  4. #4

    Custom graphic to TImage

    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)

    [pascal]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;[/pascal]
    "All paid jobs absorb and degrade the mind."
    <br />-- Aristotle

  5. #5

    Custom graphic to TImage

    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 ::

    [pascal]
    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;
    [/pascal]

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

    If any ones intrested i can post the complete source code for my texture unit?!
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  6. #6

    Custom graphic to TImage

    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?
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  7. #7

    Custom graphic to TImage

    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.

  8. #8

    Custom graphic to TImage

    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..
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •