c # flip effect

With c # and GDI + to achieve magazine flip animation time: 2010-01-13 blog.csdn.net Duke - 
Description: I am involved in a previous project an electronic magazine, was required to achieve the simulation of real-life magazine flip animation, others recommend the article, and finally achieve the effect I want, today, this article attempts to translate a bit. Want to help English proficiency is not good peers. If your English is good enough, I recommend you read the original English site at: HTTP: // www.codeproject.com/KB/GDI-plus/TurnThePage.aspx, and hope you will forgive my translation level. 
 
Introduction 
 
 
Figure 1 flip effect 
 
This article describes how to flip effect upon the creation of a picture displayed side by side in the e-book or electronic album, this book page flip effect mimics the reality of the situation. 
 
Background 
 
inspiration in writing this article from a reusable component used to display the picture of demand. I use C # and GDI + to improve my understanding of the graphic image of .net Programming. 
 
Creating this effect technical background comes from an article "FalshMX the flip effect," at: HTTP : // www.oreillynet.com/pub/a/javascript/2004/09/03/flashhacks.html, The author is Sham Bhangal. Sham how to use the line of symmetry of the animation in the article to control the visible part of the page. Although the process and in GDI + in Flash MX somewhat different, but the line of symmetry is calculated by using the page visible part of this concept is the same.
 
In this article, we assume that page 3 and page 4 is the current page, and the next action is to turn to page 5 and page 6. In other words, we want to show is flip effect on page 4. 
 
Animation techniques 
 
following figure illustrates the key areas and changes in the whole area of animation. 
 
 
2 critical areas and parameters of 
 
 
paper from network programming entry: HTTP : // www.bianceng.cn/Programming/csharp/201001/14287.htm 
entire page animations can be summarized as follows:
 
 1 , fully draw out pages 3 and 4 page. After the completion of the drawing, B and C will be partially obscured on page 4 of the visible part of the original. 
 
2 , the line of symmetry is calculated and the regions B and C of the crop. 
 
3 , drawing section B. This is below a partial region (page 6). 
 
4 , according to the corresponding conversion hotspots, and accordingly rotation. 
 
5 , the drawing part C. This is the content page displayed in the page-turning 4 during its backside (page 5). 
 
Current page 
 
"FalshMX the flip effect," the article pointed out is not involved in the current page flip effect. This means that each side (page 3 and page 4) will first be carried out without any cuts and conversion page is drawn on. B and C will be the visible part of the two to draw on this page. 
 
hot spot
 
"Hot" is the word that I borrowed from "FalshMX the flip effect" in an article over. Representative fold term hotspot position on the horizontal axis in the page, indicating that the starting position of the line of symmetry. In the course of turning, it has been moved between the hot edge to the middle of the page from the book this distance. Will vary from page flip side to this page from the hotspot (x). When the hot spot reaches the intermediate position of the book, the animation stops, then X = PAGE_WIDTH. 
 
Symmetry line 
 
crease lines represent symmetrical page turning. It is used to calculate the page to participate in the visible part of the page. In the process, the control line of symmetry of two things:
 
 . 1 , B, and C portions cropped area. 
 
 
This article from the network programming entry: HTTP : // www.bianceng.cn/Programming/csharp/201001/14287_2.htm 
2 section, C coordinate conversion origin. 
 
The line of symmetry may be described by the following two equations: 
 
a = 45 + ((45 * x) / PAGE_WIDTH) 
 
H = x Tan (a) 
 
Note that the angle will change with a change of x. This equation indicates that when X = 0 when a = 45 degrees and when PAGE_WIDTH = A = X 90 degrees. 
 
When the animation starts, the X- = 0, Sections B and C are not so visible. As x increases, the line of symmetry to form a hypotenuse. Triangle determined by the three lengths: the line of symmetry, x and height h. Figure 2 shows such a situation. 
 
With the increase of x, will appear H > = cases of PAGE_WIDTH. When this occurs, the page area with the line of symmetry intersecting triangles will become a trapezoid. The height of the trapezoid is PAGE_WIDTH. Figure 1 is the case. 
 
Either triangular or trapezoidal, this routes are closed the B and C indicated two cut areas. To see the effect of this operation with the saw frame, the source code provided in the INCLUDE_DRAW_GRAPHICS_PATH this parameter is set to true on the line. Program will be drawn out of a closed path of golden profile. 
 
A partial region of 
 
this section is to reduce the turning page in the visible portion (page 4) after the portions B and C. 
 
Region Part B 
 
Part B of the other pages are flipped under the page, in this example the middle section is visible on page 6. Part B is the region with the line of symmetry is formed of a closed curve page of the cut portion. The corresponding part of the page (page 4) on top of this section will be directly cut off. Obviously, with increasing x (a also with the increase), the visible part will be increasing. 
 
To see the relationship between the area portions A and B, set INCLUDE_UNDERSIDE_PAGE_IN_ANIMATION variable is set to false. This will be removed from the portion C in animation. 
 
C region portion 
 
image area C represents the image portion of the back pages being flipped. In this case, C represents a partial region of the visible portion of the page 5. Part C is specified by the line of symmetry, but it is on this side of the page (the left side of the line of symmetry). For example, when flipping page 4, Part B will be the lower right portion of page 6, and the portion C will be the lower left part on page 5. Figure 3 shows the relationship between the B and C.
 
 
The relationship between FIGS. 3 B and C 
 
 
herein from network programming entry: HTTP : // www.bianceng.cn/Programming/csharp/201001/14287_3.htm 
when drawing portion C region, we used a background image to auxiliary, is pageUndersideImage. This reduction of the image region is determined by the new line of symmetry. 5 page image is drawn in the new buffer inside, this new image will be close to the area B portion of the drawing. 
 
B and C are connected to the partial region 
 
when the background image part C is ready, it is drawn by the following steps: 
 
First, the coordinate system to adjust focus. 
 
The rotating coordinate system 180 [ - . 2A degrees, see FIG. 4 understand their relationship. 
 
Part C contains the image drawing area to the respective coordinates ( the -X-, - PAGE_HEIGHT). 5 indicate such rotation. 
 
 
FIG adjusted to match the angle of the line of symmetry 
 
 
in FIG. 5 a rotating coordinate system 
 
I found partial regions B and C are arranged along a line of symmetry is very challenging because of the color of the current page susceptible to the "blood side" (because some of the red pixels on page 4) . When I draw a partial region B or C, I used a workaround: pixeloffsetmode specified graphic object to pixeloffsetmode . Half way drawn. 
 
G .PixelOffsetMode = PixelOffsetMode. Half;
 
I also found that the partial region C before drawing, increasing a pixel (or minus one pixel) can be prevented from rotating coordinate the "blood side." 
 
PathTranslationMatrix .translate (( a float ) + hotSpot.Origin.X. 1, 
 
( a float ) hotSpot.Origin. The Y); 
 
To pixeloffsetmode workaround, USE_PIXEL_MODE_OFFSET provided in the source code set to true. 
 
 
- 
 
This article from the network programming entry: HTTP : // www.bianceng.cn/Programming/csharp/201001/14287_4.htm 
drawn animation 
 
each frame of animation is drawn to the buffer CurrentShownBitmap objects in timer1_Tick method. CurrentShownBitmap method is only to draw on the screen. 
 
Function mainly described 
 
calculation in each frame of the animation and the image B of Part C is done by the following method: 
 
Private the GraphicsPath GetPageUnderGraphicsPath (int X, 
 
refdouble A , int height, int width, 
 
BOOL isUnderSide , TurnType type)
 
Parameter x represents the distance from the edge of the page at the hot spot to the (previously described), height and width parameters representative of the current page height and width to be displayed. isUnderSide parameter is used to tell the program whether the calculation of C section area (the back is turning that page), the last parameter type is a page turning left or right page. Substantially, isUnderSide and type parameter is used to obtain the pattern accuracy of the path, as described above is a parameter representing the current angle. A transmission parameter is a reference, then for rotating the coordinates before drawing C (see FIG. 4 and FIG. 5). 
 
Use Code 
 
install controls 
 
the sake of simplicity, this control has its own picture. Initialization code image in LoadSamples () method. This method is called in the constructor method Sample class. 
 
Controlling the speed and number of page 
 
turning speed is controlled by a timer, it can be used to control the public property TickSpeed turning speed (in milliseconds), to animation frames each timer interval is the distance to move a hotspot controlling. public attribute to control exposure to the outside world has moved a distance x. 
 
Adjust the height of 
 
cut along the top of the back page is a problem, public property HeightAdjustment leave some blank area for easy cutting at the top of the control. 
 
The animation starts 
 
this component exposes two methods to start the animation. 
 
animateRightPageTurn () and animateLeftPageTurn () . 
 
Note 
 
I was trying to puzzle when H = H = nonlinear equations when the X-PAGE_HEIGHT Tan (45 + ((45 * (the X-)) /The value of x PAGE_WIDTH)) in my brute force approach of this code is contained in the source code. Is not there a more elegant way to do it? 
 
Description: The program source code to HTTP : // download.csdn.net/source/381727 download. 
 
 
This article from the network programming entry: HTTP : // www.bianceng.cn/Programming/csharp/201001/14287_5.htm
View Code

With c # and GDI + to achieve flip animation magazine Detailed

Description: I am involved in a previous project an electronic magazine, was required to achieve the simulation of real-life magazine flip animation effects, others recommend the article, and finally achieve the effect I want, today, to try to translate the article a bit . Want to help English proficiency is not good peers. If your English is good enough, I recommend you read the original English site at: HTTP: // www.codeproject.com/KB/GDI-plus/TurnThePage.ASPx, and hope you will forgive my translation level. 
  Introduction 

  Figure 1 flip effect 
  This article describes how to flip effect upon the creation of a picture displayed side by side in the e-book or electronic album, this book page flip effect mimics the reality of the situation. 
  Background 
  inspiration in writing this article from a reusable component used to display the picture of demand. I use C # and GDI + to improve my understanding of the graphic image of .net Programming. 
  Creating this effect technical background comes from an article "FalshMX the flip effect," at: HTTP: // www.oreillynet.com/pub/a/JavaScript/2004/09/03/flashhacks.html, The author is Sham Bhangal. Sham how to use the line of symmetry of the animation in the article to control the visible part of the page. Although the process and in GDI + in Flash MX somewhat different, but the line of symmetry is calculated by using the page visible part of this concept is the same. 
  In this article, we assume that page 3 and page 4 is the current page, and the next action is to turn to page 5 and page 6. In other words, we want to show is flip effect on page 4. 
  Animation techniques 
  following figure illustrates the key areas and changes in the whole area of animation.

2 and FIG critical region parameters 
  entire page turning animation can be summarized as: 
  1 , fully drawn pages 3 and p 4. After the completion of the drawing, B and C will be partially obscured on page 4 of the visible part of the original.
  2 , the line of symmetry is calculated and the regions B and C of the crop.
  3 , drawing section B. This is below a partial region (page 6).
  4 , according to the corresponding conversion hotspots, and accordingly rotation.
  5 , the drawing part C. This is the content page displayed in the page-turning 4 during its backside (page 5). 
  Current page 
  "FalshMX the flip effect," the article pointed out is not involved in the current page flip effect. This means that each side (page 3 and page 4) will first be carried out without any cuts and conversion page is drawn on. B and C will be the visible part of the two to draw on this page. 
  Hot 
  "Hot" is the word that I borrowed from "FalshMX the flip effect" in an article over. Representative fold term hotspot position on the horizontal axis in the page, indicating that the starting position of the line of symmetry. In the course of turning, it has been moved between the hot edge to the middle of the page from the book this distance. Will vary from page flip side to this page from the hotspot (x). When the hot spot reaches the intermediate position of the book, the animation stops, then X = PAGE_WIDTH. 
  Symmetry line 
  crease lines represent symmetrical page turning. It is used to calculate the page to participate in the visible part of the page. In the process, the control line of symmetry of two things: 
  . 1 , B, and C portions cropped area.
  2 , part C is the origin of the coordinate transformation.
  The line of symmetry may be described by the following two equations: 
  a = 45 + (( 45 * x) / PAGE_WIDTH) 
  H = x Tan (a) 
  Note that the angle will change with a change of x. This equation indicates that when X = 0 when a = 45 degrees and when PAGE_WIDTH = A = X 90 degrees. 
  When the animation starts, X = 0 , B and C portions are not so visible. As x increases, the line of symmetry to form a hypotenuse. Triangle determined by the three lengths: the line of symmetry, x and height h. Figure 2 shows such a situation. 
With the increase of x, will appear H > = cases of PAGE_WIDTH. When this occurs, the page area with the line of symmetry intersecting triangles will become a trapezoid. The height of the trapezoid is PAGE_WIDTH. Figure 1 is the case. 
  Either triangular or trapezoidal, this routes are closed the B and C indicated two cut areas. To see the effect of this operation with the saw frame, the source code provided in the INCLUDE_DRAW_GRAPHICS_PATH this parameter is set to true on the line. Program will be drawn out of a closed path of golden profile. 
  A partial region of 
  this section is to reduce the turning page in the visible portion (page 4) after the portions B and C.
  Part B region
  Part B of the other pages are flipped under the page, in this example the middle section is visible on page 6. Part B is the region with the line of symmetry is formed of a closed curve page of the cut portion. The corresponding part of the page (page 4) on top of this section will be directly cut off. Obviously, with increasing x (a also with the increase), the visible part will be increasing. 
  To see the relationship between the area portions A and B, set INCLUDE_UNDERSIDE_PAGE_IN_ANIMATION variable is set to false. This will be removed from the portion C in animation. 
  C region portion 
  image area C represents the image portion of the back pages being flipped. In this case, C represents a partial region of the visible portion of the page 5. Part C is specified by the line of symmetry, but it is on this side of the page (the left side of the line of symmetry). For example, when flipping page 4, Part B will be the lower right portion of page 6, and the portion C will be the lower left part on page 5. Figure 3 shows the relationship between the B and C. 

  The relationship between FIGS. 3 B and C 
  at the drawing portion C region, we used to assist a background image, is pageUndersideImage. This reduction of the image region is determined by the new line of symmetry. 5 page image is drawn in the new buffer inside, this new image will be close to the area B portion of the drawing. 
B and C are connected to the partial region 
  when the background image part C is ready, it is drawn by the following steps: 
  First, the coordinate system to adjust focus. 
  The rotating coordinate system 180 [ - . 2A degrees, see FIG. 4 understand their relationship. 
  Part C contains the image drawing area to the respective coordinates ( the -X-, - PAGE_HEIGHT). 5 indicate such rotation. 

  FIG 4 adjusted to match the angle of the symmetry line

  FIG 5 rotating coordinate system 
  I found that the partial region B, and C are arranged along a line of symmetry is very challenging because of the color of the current page susceptible to the "blood side" (because some of the red pixels on page 4). When I draw a partial region B or C, I used a workaround: pixeloffsetmode specified graphic object drawn in pixeloffsetmode.half manner. 
  g.PixelOffsetMode = PixelOffsetMode.Half; 
  I have also found that the partial region C prior to the drawing, increasing a pixel (or minus one pixel) can be prevented from rotating coordinate the "blood side." 
  PathTranslationMatrix.Translate (( a float ) + hotSpot.Origin.X . 1 , 
  ( a float ) hotSpot.Origin.Y); 
  To pixeloffsetmode workaround, source code USE_PIXEL_MODE_OFFSET set to true. 
  Animates 
  each frame of animation is drawn on the object buffer CurrentShownBitmap timer1_Tick process. CurrentShownBitmap method is only to draw on the screen. 
  Function mainly described 
  calculation in each frame of the image B and Part C animation is done by the following method: 
  Private the GraphicsPath GetPageUnderGraphicsPath ( intx, 
  refdouble A, int height, int width,
  BOOL isUnderSide, TurnType type) 
  parameter x represents the distance from the edge of the page at the hot spot to the (previously described), height and width parameters representative of the current page height and width to be displayed. isUnderSide parameter is used to tell the program whether the calculation of C section area (the back is turning that page), the last parameter type is a page turning left or right page. Substantially, isUnderSide and type parameter is used to obtain the pattern accuracy of the path, as described above is a parameter representing the current angle. A transmission parameter is a reference, then for rotating the coordinates before drawing C (see FIG. 4 and FIG. 5). 
  Use Code 
  install controls 
  the sake of simplicity, this control has its own picture. Initialization code image in LoadSamples () method. This method is called in the constructor method Sample class. 
  Controlling the speed and number of page 
  turning speed is controlled by a timer, it can be used to control the public property TickSpeed turning speed (in milliseconds), to animation frames each timer interval is the distance to move a hotspot controlling. public attribute to control exposure to the outside world has moved a distance x. 
  Adjust the height of 
  cut along the top of the back page is a problem, public property HeightAdjustment for leaving a blank area to facilitate cutting the top of the control. 
  Start animation 
  this component exposes two methods to start the animation.
  animateRightPageTurn () and animateLeftPageTurn (). 
  Note 
  I was trying to puzzle when h = h when the nonlinear equation x = Tan PAGE_HEIGHT ( 45 + (( 45 * (x)) / x value in PAGE_WIDTH)), I this brute force approach of the code contained in the source code. Is not there a more elegant way to do it? 
  Description: The program source code to HTTP: // download.csdn.net/source/381727 download.
 
View Code

 

Guess you like

Origin www.cnblogs.com/blogpro/p/11465115.html