Photoshop Flow Selection Border

zhaozj2021-02-16  52

Learning programming is really a hard thing. However, for those who have programmed, it is also true that it is true. When we can't achieve a function, we will not feel distressed, and strong curware is enough to make us forget everything. And when we finally realized, the kind of Liu dark flower, suddenly turned out, and the mysterious feelings that saw the sunrise is really unable to say. I believe that most shared software, free software is not because the author doesn't want to make money, but because the programmer is more willing to show off his own intervention.

There are a lot of learning and programming, ask me, how to improve your level. Oh, my answer may be a bit different from others. I think not to hold books, and all make it to understand and then program. You can do it if you know. What do we have? Very simple, we try to achieve the functions implemented in other excellent software, see if we can implement it. In this way, everyone's level must be improved soon.

For example, how is the spray gun in Potoshop?

We can think about it: The shape of the gun can be obtained by changing the shape of the mouse so that we will further. We simplify the rest of the problem, you can not consider the strength of the gun, and simplify the problem into how to draw a certain range around the mouse. The specific method doesn't need me to come again? Then we slowly add other features such as linear, color, and strength, and the gun is completed.

Today I am going to implement the selection border function flowing in Potoshop.

In Potoshop, when we choose some graphics, its selection border is a flow. In other drawings, it is not the case, such as Acdsee. If you use this feature in our program, it feels very cool. However, what is it realized?

I thought it was very simple at first. Is the rectangular flow pick border easy to implement? However, in the potoshop, other irregular selection borders such as the rope are flow type.

I solve this problem like this.

First, when you don't know how to start, choose the right keyword to find information. What words do you choose? This is to rely on personal experience. I noticed two words that "Line" and "Path" (PATH). You will choose the word LINE first? Why do I choose PATH? Oh, this is feeling, I can't say it, but as you have more and more programmed (actually, I have edited the handline of the hollow word, so I have experienced this experience). Try less nonsense, try the help of the help, but also don't have to use MSDN. Open Delphi's Help Help -> Windows SDK, enter keyword line or pat, really good, come out a bunch of functions. No matter if you use it, let's take a look, just as a study. However, my luck is really good: two keywords are hit! What should I do if I don't have? Select a few more. However, don't choose.

Here, we have to read the description of the LINEDDA function.

Let's next step is to program the test test. I chose to build a flowing font border, like the effect of neon lights.

The program is as follows, I have added a detailed note. I didn't expect the program so short.

Unit unit1;

Interface

Uses

Windows, Messages, Sysutils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, ExtCtrls, stdctrls;

Type

TFORM1 = Class (TFORM)

Button1: tbutton;

Timer1: TTIMER; Procedure Button1Click (Sender: TOBJECT);

Procedure Timer1Timer (Sender: TOBJECT);

Private

{Private Declarations}

public

{Public declarations}

END;

VAR

FORM1: TFORM1;

PathPoints: array [0..1000] of tpoint;

PathTypes: array [0..1000] of byte;

PPTS: PPOINT;

PTYPES: PBYTEARRAY;

Number: integer;

Counter: Byte;

IMPLEMentation

{$ R * .dfm}

The format of // MovingDOTS is a predetermined. You can read the help of Linedda.

/ / Here I use it to define the color of the mobile line.

// Note: MOVINGDOTS is a callback function that needs to be added to the stdcall keyword.

Procedure MovingDOTS (X, Y: Integer; Thecanvas: Tcanvas); Stdcall;

Begin

If counter = 15 THEN Counter: = 0;

IF counter <5 THEN

Thecanvas.Pixels [x, y]: = CLWHITE

Else if counter <12 THEN

Thecanvas.Pixels [x, y]: = CLRED

Else

Thecanvas.pixels [x, y]: = CLBLUE;

Inc (counter);

END;

INTERVAL I // Timer1 is set to 100.

// If you feel the font flicker during programming, you can adjust the interval, mobile line color length, font

// For example, in this program, remove the font [fsital] property, you will faint.

// Even the extent of the number of words also flicker. You can only comprehensively debug these factors.

Procedure TFORM1.TIMER1TIMER (Sender: TOBJECT);

VAR

J, K: Integer;

Begin

// Do you use the PRED function? You can also replace it with Number-1 here.

/ / Do you know their difference? Haha.

For J: = 0 to Pred (Number) DO

Begin

// When the current point is connected to the next key to use MOVINGDOTS method to connect LINEDDA (PathPoints [J] .x, PathPoints [J] .x, PathPoints [J 1] .x, Pathpoints [J 1] .y,

@ MOVINGDOTS, Longint (Form1.canvas))

END;

END;

Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);

Begin

Canvas.Font.name: = 'Young round'; // The font here must be trueType Font

Canvas.font.size: = 72;

Canvas.Font.Style: = [fsitalic, fsbold]; // is preferably set to bold words, so that the contour is large

Beginpath (canvas.handle); // Start capturing the contour drawing on Canvas

// Use setBkmode to remove the text box, you can not use it, more effects

SetBkmode (canvas.handle, Transparent);

Canvas.TextOut (120, 20, 'computer');

Endpath (canvas.handle); // End capture

// Use FlattenPath to make the outline smooth, you can do it, compare the effect if Flattenpath (Canvas.Handle) THEN

Begin

// Get the contour control point

PPTS: = NIL;

PTYPES: = NIL;

Number: = getPath (canvas.handle, PPTS, PTYPES, 0);

Number: = getpath (canvas.handle, pathpoints, pathtypes, number);

END;

END;

End.

The effect is as shown:

How do you have so many miscellaneous?

In order to remove these thumbnails, I got all over the whole night. If you blame, I don't help but look good. You also track the contents of the array of PathTypes, and then read it again about it.

PT_Moveto: It is equivalent to the starting point of the line segment.

PT_Closefigure: It is equivalent to the end point of the closed curve, and the relative PT_MoveTo connection constitutes a closed curve.

Now you know that the problem is there? The example of our example "Computer" is composed of a plurality of closed curves. In our program, a curve PT_Closefigure does not constitute a closed curve with the relative PT_MoveTo connection, but is connected to the starting point of the next curve. The line segment from (0,0) point wrap is 0 due to the data after PathPoints.

I know these, the program is good. Put the following sentences to the LINEDDA function:

If pathtypes [j] = 3 THEN/ If it is the end of the curve. Why is 3?

// Note that I didn't use PT_Moveto to judge.

Begin

For K: = J Downto 0 DO

Begin

IF pathtypes [k] = 6 then // Find the corresponding curve starting point. Why is it 6?

// Note that I didn't use PT_Closefigure to judge.

Begin

// Connect the end point and the starting point to constitute a closed curve. Linedda (PathPoints [J] .x, PathPoints [J] .x, Pathpoints [K] .x, Pathpoints [K] .y,

@ MovingDOTS, Longint (Form1.canvas));

Break;

END;

END;

CONTINUE;

END;

This is ok, the effect is good? Figure:

I don't know what you have learned from this programming. You can communicate with me. My QQ number is 44065089, saying that it is a cold night to see the snow.

This program is passed under Delphi7.0 Win ME.

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

New Post(0)