Delphi
Multimedia Methods
Writing to a form's canvas - color triangles, etc. DI Aug 1995
Displaying a video on a
panel:
- MediaPlayer.DisplayRect :=
Panel1.clientRect;
Play a wav file:
- sndPlaySound('wavefile.wav',snd_Sync);
- nb. use snd_Sync
if wish to halt program whilst sound being played
otherwise use snd_ASync.
- nb. must have
MMSystem in uses clause;
Colors:
- TColor is a 4 byte
LongInt, the 1st byte determines how the color is
rendered on screen, the next 3 bytes represent blue,
green & red respectively:
- eg. $0200FF00 =
green, $02FF0000 = blue, $020000FF = red
($FF=255), $02000000 = black, $02FFFFFF = white;
Random colors: (see Delphi Informant Aug,96 pp52..)
- Randomize; {need to set
this once for the program}
- form1.color := $02000000 +
Trunc($FFFFFF * Random);
- NB. can also do this to
fill a form with random colors:
- var x, y: integer;
- begin
- for x := 0 to
Form1.ClientWidth do
- for y := 0
to Form1.ClientHeight do
- Form1.canvas.pixels[x,y]
:= the above
- end;
Tiling a bitmap on a form:
- Form.OnPaint event:
- var xPos, yPos, bmpWidth, bmpHeight: LongInt;
- begin with myBitmap do
- begin bmpWidth := Width; bmpHeight :=
Height; end;
- ypos := 0;
- while yPos < Height do
- begin
- xPos := 0;
- while xPos < width do
- begin
- Canvas.draw(xpos,ypos,myBitmap);
- xpos := xpos + bmpWidth;
- end;
- yPos := yPos + bmpHeight;
- end;
- end;
- Form.OnCreate event:
- begin
- try myBitmap := TBitmap.create;
- myBitmap.LoadFromFile(imagefile);//should be
40x40pixels in size preferably
- except myBitmap.free; end;
- end;