Results 1 to 8 of 8

Thread: Show a bitmap on a TPaintBox

  1. #1

    Show a bitmap on a TPaintBox

    Well, I'm using Lazarus but I think the question is Ok here.

    I did a program to manage data files that include bitmaps. I use a TPaintBox to show these images on the window but it's too slow because I'm using Allegro.pas not the TImage widget to load and manage the bitmap images. The function that manages the "OnPaint" message of the TPaintBox is similar than this (sort of pseudocode):
    [pascal]procedure TForm1.PaintBox1Paint(Sender: TObject);
    VAR
    X, Y: INTEGER;
    ImageBox: TImageBox;
    begin
    ImageBox := Sender;
    FOR Y := 0 TO (Image^.h - 1) DO
    FOR X := 0 TO (Image^.w - 1) DO
    ImageBox.canvas.drawpixel (X, Y, al_getpixel (Image, X, Y));
    end;
    [/pascal] That is, I copy the image pixel-to-pixel.

    As I've said this is too slow and I'm wondering if there's a faster way to do it. The "Image" object also has a pointer to the raw data named "data" that stores the color information in 8, 15, 16, 24 or 32 bits-per-pixel.

    May be I can do something as:[pascal]procedure TForm1.PaintBox1Paint(Sender: TObject);
    VAR
    ImageBox: TImageBox;
    Copy: AL_BITMAPptr;
    begin
    Copy := copy_bitmap_to_32bpp (Image);
    ImageBox := Sender;
    ImageBox.Canvas.DrawRawImage (Copy^w, Copy^.h, Copy^.data); { Is there such method? }
    al_destroy_bitmap (Copy);
    end;
    [/pascal] Where copy_bitmap_to_32bpp creates a copy of "Image" in 32bpp for sure and the "DrawRawImgage" method is an optimised function that draws a "raw 32bpp bitmap" in the TPaintBox' canvas.

    How can I do that?
    No signature provided yet.

  2. #2

    Show a bitmap on a TPaintBox

    I think it's faster to create a TBitmap, and copy your data into it (using scanline), and draw the bitmap onto the paintbox by calling (Canvas.Draw(X, Y, *Bitmap Here*), if i recall correctly).

    I'm sure you can find plenty examples using TBitmap's scanline functionality. Check google and the delphi help.

    Good luck!
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  3. #3

    Show a bitmap on a TPaintBox

    I'll save you some googling time. This reference is very cool, check it out:

    http://www.efg2.com/Lab/ImageProcessing/Scanline.htm

  4. #4

    Show a bitmap on a TPaintBox

    Thanks. I'll read it.

    [edit] Seems as Lazarus' TBitmap hasn't the scanline property or I can't find it.
    No signature provided yet.

  5. #5

    Show a bitmap on a TPaintBox

    That's right, you have to use TLazInfImage instead. You can keep using TBitmap, but when you need the Scanline, just create a copy in a TLazInfImage and work on it... I don't understand why they made it that way, but I use it in my own engine and works fine. You can see more about that in:

    http://wiki.lazarus.freepascal.org/D...th_Graphics/es
    http://www.lazarus.freepascal.org/lc...IntfImage.html

    Saludos!!

  6. #6

    Show a bitmap on a TPaintBox

    I see. That's weird but may be they do this way to keep compatibility with the Free Pascal RTL. :?

    Gracias.
    No signature provided yet.

  7. #7

    Show a bitmap on a TPaintBox

    I see. That's weird but may be they do this way to keep compatibility with the Free Pascal RTL. :?

    Gracias.
    No signature provided yet.

  8. #8

    Show a bitmap on a TPaintBox

    [edit] Something was wrong with my connexion :?[/edit]

    I see. That's weird but may be they do this way to keep compatibility with the Free Pascal RTL. :?

    Gracias.
    No signature provided yet.

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
  •