Graphic display skills in Delphi

zhaozj2021-02-08  273

(06/11/1999) Overview ---- Currently in many learning software, in the game CD, you often see various graphic display skills, with graphical movement, interleave, raindrops, 100-page window, blocks stack, etc. The way of appearance makes the picture more lively and attracts the audience. This article will explore how to implement a variety of graphic display skills in Delphi. Basic principle ---- In Delphi, the display of a pair image is very simple, as long as a TIMAGE component is defined in the Form, set its Picture property, then select any valid .ico, .bmp, .emf or .Wmf file, perform LOAD, the selected file is displayed in the TIMAGE component. But this is just directly displaying the graphic in the form, and there is no skill. In order to display the graphic display with a unique effect, you can implement: --- Define a TIMAGE component, put the graphic to the TIMAGE component, that is, put the graphic content from the disk into the memory , As a graphical cache. ---- Create a new bitmap object whose size is the same as the graphics in the TIMAGE component. ---- Use the copyrect function of Canvas (copy a rectangular area of ​​the canvas to another canvas to another canvas), use the skill, dynamically configured the bitmap file content, and then display the bitmap in the form. ---- Implementation Method The following describes the various graphic display skills: 1. The push-pull effect will be drawn from the top, bottom, left, and right directions, cover the original old chart on the screen, this kind The effect can be divided into four kinds, pull, pull, pull left, right pull, but the principle is similar, the above is the case. Principle: First, the first horizontal line of the temporary graph is moved to move to the last one of the bitmap to display, then move the first two horizontal lines of the temporary graphic to display the last two of the bitmap. The horizontal line, then move the top three, the first four 叁 叁 until all graphics data are finished. You can see the displayed bitmap from the bottom to float up and up to the effect of the pull-up. 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 interleave effect principle: Demolition of graphics to display into two parts, odd number of scan lines Move down, the part of the even scan line is moved up, and both are carried out simultaneously. From the screen, you can see the center of moving the side of the upper and lower ends to the center of the screen until it is fully 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; 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. Level interleave effect principle: Like the principle of vertical interleaving effect, it is only moving into the screen from the left and right ends. 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; 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, 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; new; 4. Rain effect principle: The last scan line of the telecommunications graphic is moved to the first scan line of the visible bitmap, let this The scan line leaves its trajectory on the screen. Then, the reciprocal second screen of the temporary dramatic graph is then moved to the first torsion of the visual position to the second scan line. The remaining scan lines are pushed accordingly.

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; bmpWidth: = image1.width; for i: = bmpheight downto 1 do for i: = 1 to i do begin newbmp.canvas.copyRect (RECT (0, J-1, BMPWIDTH , i), image1.canvas, reference (0, i-1, bmpwidth, i)); Form1.canvas.DRAW (120, 100, newbmp); end; newbmp.free; end; 5. Blonde effect principle: will be put The data of the temporary graph is divided into several groups, and then move from the first set to the last set, the first time each group moves the first scan line to the respective position of the visible position, the second movement second scan Line, then move the third, fourth scan line. 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, B Mpwidth, xcount * j i); form1.canvas.draw (120, 100, newbmp); end; newbmp.free; end; 6. The principle of building blocks: a change in raindrop effects, different, building block effect Each time you move is a graphic, not just a scan line.

转载请注明原文地址:https://www.9cbs.com/read-1523.html

New Post(0)