Forum > Graphics

How Can i Draw a bitmap without paintBox control

(1/1)

sun_catboy:
I want to write a game ,but i need to draw some bitmap or jpg,but don't use paintbox,I try many ways to do this,but i can't! anyone can help me? Thinks a lot .

Spribo:
Have you tried TImage? You can set its Picture property to a desired image(a files browser window opens  hitting the ... button in the box of the property in Object Inspector). I think that you could create all these TImages and then set and unset their Visible property to TRUE, but you can also dynamically assing an image to a TImage's Picture property, although I personally don't know how to do this.

xqtr:
There are many ways... you can draw at the form canvas it self, directly... you can make new custom TGraphicControl components, you can draw your graphics on Tbitmaps and then draw them onto the form or a Timage component.

In general... you can draw on any component that has a Canvas property.

sun_catboy:
I'm not use the LCL, just uses the kol-ce ,but there is no TImage

sun_catboy:
This is my code,I's use the kol-ce.

{ KOL MCK }
{$DEFINE KOL_MCK}
{$ifdef FPC}
        {$mode delphi}
{$endif}
program project1;

uses
  KOL,Windows,ImageDecompress;
var
 MainForm:PControl;
 image: pImageDecompress;

procedure PaintBack( Sender: PControl; DC: HDC );
var
aRect: tRect;
begin
    aRect.Left:= 0;
    aRect.Top := 0;
    aRect.Right  := 240;
    aRect.Bottom := 320;
    if image<> nil then
    image.Bitmap.StretchDraw (DC, aRect);//This will be exception :-(
end;


{$IFDEF WINDOWS}{$R project1.rc}{$ENDIF}

begin
 image:=newImageDecompress;
 image.LoadFromFile('1.jpg');
 MainForm:=NewForm(Applet,'TestApp');
 MainForm.Show;
 MainForm.OnPaint:=TOnPaint(MakeMethod(nil,@PaintBack));
 Run(MainForm);
 image.Free;
 MainForm.Free;
end.     

Navigation

[0] Message Index

Go to full version