BVB Source Codes

PDF file browser Show Images.cs Source code

Return Download PDF file browser: download Images.cs Source code - Download PDF file browser Source code - Type:.cs
  1. using System;
  2. using System.Diagnostics;
  3. using System.Drawing;
  4. using PdfSharp.Drawing;
  5. using PdfSharp.Pdf;
  6.  
  7. namespace Graphics
  8. {
  9.   /// <summary>
  10.   /// Shows how to draw images.
  11.   /// </summary>
  12.   public class Images : Base
  13.   {
  14.     string jpegSamplePath = "../../../../XGraphicsLab/images/Z3.jpg";
  15.     string gifSamplePath  = "../../../../XGraphicsLab/images/Test.gif";
  16.     string pngSamplePath  = "../../../../XGraphicsLab/images/Test.png";
  17.     string tiffSamplePath = "../../../../XGraphicsLab/images/Rose (RGB 8).tif";
  18.     string pdfSamplePath = "../../../../XGraphicsLab/images/SomeLayout.pdf";
  19.  
  20.     public void DrawPage(PdfPage page)
  21.     {
  22.       XGraphics gfx = XGraphics.FromPdfPage(page);
  23.  
  24.       DrawTitle(page, gfx, "Images");
  25.  
  26.       DrawImage(gfx, 1);
  27.       DrawImageScaled(gfx, 2);
  28.       DrawImageRotated(gfx, 3);
  29.       DrawImageSheared(gfx, 4);
  30.       DrawGif(gfx, 5);
  31.       DrawPng(gfx, 6);
  32.       DrawTiff(gfx, 7);
  33.       DrawFormXObject(gfx, 8);
  34.     }
  35.  
  36.     /// <summary>
  37.     /// Draws an image in original size.
  38.     /// </summary>
  39.     void DrawImage(XGraphics gfx, int number)
  40.     {
  41.       BeginBox(gfx, number, "DrawImage (original)");
  42.  
  43.       XImage image = XImage.FromFile(jpegSamplePath);
  44.  
  45.       // Left position in point
  46.       double x = (250 - image.Width * 72 / image.HorizontalResolution) / 2;
  47.       gfx.DrawImage(image, x, 0);
  48.  
  49.       EndBox(gfx);
  50.     }
  51.  
  52.     /// <summary>
  53.     /// Draws an image scaled.
  54.     /// </summary>
  55.     void DrawImageScaled(XGraphics gfx, int number)
  56.     {
  57.       BeginBox(gfx, number, "DrawImage (scaled)");
  58.  
  59.       XImage image = XImage.FromFile(jpegSamplePath);
  60.       gfx.DrawImage(image, 0, 0, 250, 140);
  61.  
  62.       EndBox(gfx);
  63.     }
  64.  
  65.     /// <summary>
  66.     /// Draws an image transformed.
  67.     /// </summary>
  68.     void DrawImageRotated(XGraphics gfx, int number)
  69.     {
  70.       BeginBox(gfx, number, "DrawImage (rotated)");
  71.  
  72.       XImage image = XImage.FromFile(jpegSamplePath);
  73.  
  74.       double dx = 250, dy = 140;
  75.  
  76.       gfx.TranslateTransform(dx / 2, dy / 2);
  77.       gfx.ScaleTransform(0.7);
  78.       gfx.RotateTransform(-25);
  79.       gfx.TranslateTransform(-dx / 2, -dy / 2);
  80.  
  81.       XMatrix matrix = XMatrix.Identity;
  82.  
  83.       double width  = image.Width  * 72 / image.HorizontalResolution;
  84.       double height = image.Height * 72 / image.HorizontalResolution;
  85.  
  86.       gfx.DrawImage(image, (dx - width) / 2, 0, width, height);
  87.  
  88.       EndBox(gfx);
  89.     }
  90.  
  91.     /// <summary>
  92.     /// Draws an image transformed.
  93.     /// </summary>
  94.     void DrawImageSheared(XGraphics gfx, int number)
  95.     {
  96.       BeginBox(gfx, number, "DrawImage (sheared)");
  97.  
  98.       XImage image = XImage.FromFile(jpegSamplePath);
  99.  
  100.       double dx = 250, dy = 140;
  101.  
  102.       XMatrix matrix = gfx.Transform;
  103.       matrix.Translate(dx / 2, dy / 2);
  104.       matrix.Scale(-0.7, 0.7);
  105.       matrix.Shear(-0.4, -0.3);
  106.       matrix.Translate(-dx / 2, -dy / 2);
  107.       gfx.Transform = matrix;
  108.  
  109.       double width  = image.Width  * 72 / image.HorizontalResolution;
  110.       double height = image.Height * 72 / image.HorizontalResolution;
  111.  
  112.       gfx.DrawImage(image, (dx - width) / 2, 0, width, height);
  113.  
  114.       EndBox(gfx);
  115.     }
  116.  
  117.     /// <summary>
  118.     /// Draws a GIF image with transparency.
  119.     /// </summary>
  120.     void DrawGif(XGraphics gfx, int number)
  121.     {
  122.       this.backColor = XColors.LightGoldenrodYellow;
  123.       this.borderPen = new XPen(XColor.FromArgb(202, 121, 74), this.borderWidth);
  124.       BeginBox(gfx, number, "DrawImage (GIF)");
  125.  
  126.       XImage image = XImage.FromFile(gifSamplePath);
  127.  
  128.       double dx = 250, dy = 140;
  129.  
  130.       double width  = image.Width  * 72 / image.HorizontalResolution;
  131.       double height = image.Height * 72 / image.HorizontalResolution;
  132.  
  133.       gfx.DrawImage(image, (dx - width) / 2, (dy - height) / 2, width, height);
  134.  
  135.       EndBox(gfx);
  136.     }
  137.  
  138.     /// <summary>
  139.     /// Draws a PNG image with transparency.
  140.     /// </summary>
  141.     void DrawPng(XGraphics gfx, int number)
  142.     {
  143.       BeginBox(gfx, number, "DrawImage (PNG)");
  144.  
  145.       XImage image = XImage.FromFile(pngSamplePath);
  146.  
  147.       double dx = 250, dy = 140;
  148.  
  149.       double width  = image.Width  * 72 / image.HorizontalResolution;
  150.       double height = image.Height * 72 / image.HorizontalResolution;
  151.  
  152.       gfx.DrawImage(image, (dx - width) / 2, (dy - height) / 2, width, height);
  153.  
  154.       EndBox(gfx);
  155.     }
  156.  
  157.     /// <summary>
  158.     /// Draws a TIFF image with transparency.
  159.     /// </summary>
  160.     void DrawTiff(XGraphics gfx, int number)
  161.     {
  162.       XColor backColor = this.backColor;
  163.       this.backColor = XColors.LightGoldenrodYellow;
  164.       BeginBox(gfx, number, "DrawImage (TIFF)");
  165.  
  166.       XImage image = XImage.FromFile(tiffSamplePath);
  167.  
  168.       double dx = 250, dy = 140;
  169.  
  170.       double width  = image.Width  * 72 / image.HorizontalResolution;
  171.       double height = image.Height * 72 / image.HorizontalResolution;
  172.  
  173.       gfx.DrawImage(image, (dx - width) / 2, (dy - height) / 2, width, height);
  174.  
  175.       EndBox(gfx);
  176.       this.backColor = backColor;
  177.     }
  178.  
  179.     /// <summary>
  180.     /// Draws a form XObject (a page from an external PDF file).
  181.     /// </summary>
  182.     void DrawFormXObject(XGraphics gfx, int number)
  183.     {
  184.       //this.backColor = XColors.LightSalmon;
  185.       BeginBox(gfx, number, "DrawImage (Form XObject)");
  186.  
  187.       XImage image = XImage.FromFile(pdfSamplePath);
  188.  
  189.       double dx = 250, dy = 140;
  190.  
  191.       gfx.TranslateTransform(dx / 2, dy / 2);
  192.       gfx.ScaleTransform(0.35);
  193.       gfx.TranslateTransform(-dx / 2, -dy / 2);
  194.  
  195.       double width  = image.Width  * 72 / image.HorizontalResolution;
  196.       double height = image.Height * 72 / image.HorizontalResolution;
  197.  
  198.       gfx.DrawImage(image, (dx - width) / 2, (dy - height) / 2, width, height);
  199.  
  200.       EndBox(gfx);
  201.     }
  202.   }
  203. }
  204.  
downloadImages.cs Source code - Download PDF file browser Source code
Related Source Codes/Software:
Campus id - This system includes a campus dormitory management... 2015-04-10
ShopXP online system source code - ShopXP ShoppingNet online system source code infor... 2015-04-10
TOM cat demo in learning to speak - 实现汤米猫学说话的演示,即实现变声功能鲜豔,,,,,,,开发者说:自己经常来看code4app,看看... 2015-04-10
Another OpenFolder - Implements can commence in the middle of the scree... 2015-04-10
Bus query system - A simple bus query system. Can be divided into rou... 2015-04-10
Customer service management system - To a store and development of customer service man... 2015-04-10
OA office automation system - OA office automation system is tomorrow technology... 2015-04-10
Chapters novel divider (ChapCuttor) - Chapter divider (ChapCuttor) by & have spent Black... 2015-04-10
Graduation design file (graphics algorithm design) - Reference image effect algorithm design the softwa... 2015-04-10
CheatEngine5.6 source code - Game cheat the 5.6 version of the source code, it ... 2015-04-10
Online ZhaXunWang science formula query V1.0 - Including junior middle school and high school sci... 2016-10-20
Observe science formula query v1.0 - Observe network science formulas 2016-10-20
Lele v1.1 QQ login system - "Le Le QQ Group landing system Ver1.1" * Fix QQ ... 2016-10-20
The new network domain name host distribution system V1.0 - Use Notepad to open \Global.asa idc1688 into your ... 2016-10-20
QQ group v2.1 release system - ha ha - "Copyright" This system is based on the Wu Meng de... 2016-10-20
Interesting content ASPCMS v1.0 - Update log: 2016-10-20
Residential feng shui fortune-telling v1.0 - The project according to the orientation of the ar... 2016-10-20
The self-help chain home beautiful - The self-help chain home beautiful 2016-10-20
EXW FLASH web site management system v2.0 - EXW FLASH introduction: EXW website management sys... 2016-10-20
WAP2.0 web site management system V1.0 - System installation steps 1, install the QuickWAP ... 2016-10-20

 Back to top