Overview
----At present, in many learning software and game CDs, you can often see various
Graphic display technology relies on the movement, interlacing, raindrop shape, blinds, building block stacking and other display methods of graphics to make the picture more lively and more attractive to the audience. This article will explore how to implement various graphic display techniques in Delphi.
Basic principles
----In Delphi, it is very simple to display an image. Just define a TImage component in the Form, set its picture attribute, and then select any valid .ICO, .BMP, .EMF or .WMF File, load, and the selected file will be displayed in the TImage component. But this just displays the graphics directly in the form, and there is no skill at all. In order to make the graphic display have a unique effect, you can follow the following steps:
----Define a TImage component, and load the graphics to be displayed into the TImage component first. In other words, load the graphics content from the disk into the memory as a graphics cache.
----Create a new bitmap object with the same size as the graphics in the TImage component.
----Use the CopyRect function of Canvas (copy the rectangular area of one canvas to the rectangular area of another canvas), use techniques, and dynamically shape
Convert the file contents into a bitmap and then display the bitmap in the form.
----Implementation method
Various graphic display techniques are introduced below:
1.Push-pull effect
The graphics to be displayed are pulled into the screen from up, down, left and right directions, and the original old graphics on the screen are covered up at the same time. This effect can be divided into four
There are three types: pull-up, pull-down, left-pull, and right-pull, but the principles are similar. Take the pull-up effect as an example.
Principle: First, move the first horizontal line in the temporary graphic to the last one in the bitmap to be displayed, and then move the first two horizontal lines in the temporary graphic to the last two bitmaps to be displayed. Horizontal lines, and then move the first three and first four??? until all the graphic data is moved. During the moving process, you can see that the displayed bitmap floats from bottom to top, achieving a pull-up effect.
Program algorithm:
PRocedure TForm1.Button1Click(Sender: TObject);
var
newbmp: TBitmap;
i,bmpheight,bmpwidth:integer;
begin
newbmp:= TBitmap.Create;
newbmp.Width:=image1.Width;
newbmp.Height:=image1.Height;
bmpheight:=image1.Height;
bmpwidth:=image1.Width;
for i:=0 to bmpheight do
begin
newbmp.Canvas.CopyRect(Rect
(0,bmpheight-i,bmpwidth,bmpheight),
image1.Canvas,
Rect(0,0,bmpwidth,i));
form1.Canvas.Draw(120,100,newbmp);
end;
newbmp.free;
end;
2. Vertical staggered effect
Principle: Split the graphics to be displayed into two parts. The odd-numbered scan lines are moved from top to bottom, and the even-numbered scan lines are moved from bottom to top, and both are performed at the same time. From the screen, you can see that the lighter graphics appearing at the upper and lower ends move towards the center of the screen until they are completely clear.
Program algorithm:
procedure TForm1.Button4Click(Sender: TObject);
var
newbmp:TBitmap;
i,j,bmpheight,bmpwidth:integer;
begin
newbmp:= TBitmap.Create;
newbmp.Width:=image1.Width;
newbmp.Height:=image1.Height;
bmpheight:=image1.Height;
bmpwidth:=image1.Width;
i:=0;
while i< =bmpheight do
begin
j:=i;
while j>0 do
begin
newbmp.Canvas.CopyRect(Rect(0,j-1,bmpwidth,j),
image1.Canvas,
Rect(0,bmpheight-i+j-1,bmpwidth,bmpheight-i+j));
newbmp.Canvas.CopyRect(Rect
(0,bmpheight-j,bmpwidth,bmpheight-j+1),
image1.Canvas,
Rect(0,ij,bmpwidth,i-j+1));
j:=j-2;
end;
form1.Canvas.Draw(120,100,newbmp);
i:=i+2;
end;
newbmp.free;
end;
3. Horizontal staggered effect
Principle: The same principle as the vertical interlacing effect, except that the graphics divided into two groups are moved into the screen from the left and right ends respectively.
Program algorithm:
procedure TForm1.Button5Click(Sender: TObject);
var
newbmp:TBitmap;
i,j,bmpheight,bmpwidth:integer;
begin
newbmp:= TBitmap.Create;
newbmp.Width:=image1.Width;
newbmp.Height:=image1.Height;
bmpheight:=image1.Height;
bmpwidth:=image1.Width;
i:=0;
while i< =bmpwidth do
begin
j:=i;
while j>0 do
begin
newbmp.Canvas.CopyRect(Rect(j-1,0,j,bmpheight),
image1.Canvas,
Rect(bmpwidth-i+j-1,0,bmpwidth-i+j,bmpheight));
newbmp.Canvas.CopyRect(Rect
(bmpwidth-j,0,bmpwidth-j+1,bmpheight),
image1.Canvas,
Rect(ij,0,i-j+1,bmpheight));
j:=j-2;
end;
form1.Canvas.Draw(120,100,newbmp);
i:=i+2;
end;
newbmp.free;
end;
4. Raindrop effect
Principle: Move the last scan line of the temporary graphics to the first to the last scan line of the visible bitmap in sequence, allowing this scan line to leave its trace on the screen. Then, the penultimate scan line of the temporary graphics is moved to the first to penultimate scan lines of the visible bitmap in sequence. And so on for the remaining scan lines.
Program algorithm:
procedure TForm1.Button3Click(Sender: TObject);
var
newbmp:TBitmap;
i,j,bmpheight,bmpwidth:integer;
begin
newbmp:= TBitmap.Create;
newbmp.Width:=image1.Width;
newbmp.Height:=image1.Height;
bmpheight:=image1.Height;
bmpwidth:=image1.Width;
for i:=bmpheight downto 1 do
for j:=1 to i do
begin
newbmp.Canvas.CopyRect(Rect(0,j-1,bmpwidth,j),
image1.Canvas,
Rect(0,i-1,bmpwidth,i));
form1.Canvas.Draw(120,100,newbmp);
end;
newbmp.free;
end;
5.Louvres effect
Principle: Divide the data placed in the temporary graphics into several groups, and then move them sequentially from the first group to the last group. The first time each group moves the first scan line to the corresponding position of the visible bitmap, and the second time Move the second scan line, then move the third and fourth scan lines.
Program algorithm:
procedure TForm1.Button6Click(Sender: TObject);
var
newbmp:TBitmap;
i,j,bmpheight,bmpwidth:integer;
xgroup,xcount:integer;
begin
newbmp:= TBitmap.Create;
newbmp.Width:=image1.Width;
newbmp.Height:=image1.Height;
bmpheight:=image1.Height;
bmpwidth:=image1.Width;
xgroup:=16;
xcount:=bmpheight div xgroup;
for i:=0 to xcount do
for j:=0 to xgroup do
begin
newbmp.Canvas.CopyRect(Rect
(0,xcount*j+i-1,bmpwidth,xcount*j+i),
image1.Canvas,
Rect(0,xcount*j+i-1,bmpwidth,xcount*j+i));
form1.Canvas.Draw(120,100,newbmp);
end;
newbmp.Free;
end;
6. Building block effect
Principle: It is a variation of the raindrop effect. The difference is that the building block effect moves a piece of graphics each time, not just a scan line.
Program algorithm:
procedure TForm1.Button7Click(Sender: TObject);
var
newbmp:TBitmap;
i,j,bmpheight,bmpwidth:integer;
begin
newbmp:= TBitmap.Create;
newbmp.Width:=image1.Width;
newbmp.Height:=image1.Height;
bmpheight:=image1.Height;
bmpwidth:=image1.Width;
i:=bmpheight;
while i>0 do
begin
for j:=10 to i do
begin
newbmp.Canvas.CopyRect(Rect(0,j-10,bmpwidth,j),
image1.Canvas,
Rect(0,i-10,bmpwidth,i));
form1.Canvas.Draw(120,100,newbmp);
end;
i:=i-10;
end;
newbmp.free;
end;
Conclusion
The above graphic display effects have been passed on the computer, the software environment is Delphi 3.0, and the hardware environment is a Pentium 100M compatible machine. It works great.