Debian Codegraph @

if/c#/demo/RawImageDemo.cs

raw
1 /*
2 * << Haru Free PDF Library 2.0.5 >> -- RawImageDemo.cs
3 *
4 * Copyright (c) 1999-2006 Takeshi Kanno <[email protected]>
5 *
6 * Permission to use, copy, modify, distribute and sell this software
7 * and its documentation for any purpose is hereby granted without fee,
8 * provided that the above copyright notice appear in all copies and
9 * that both that copyright notice and this permission notice appear
10 * in supporting documentation.
11 * It is provided "as is" without express or implied warranty.
12 *
13 */
14
15 using System;
16 using System.IO;
17 using HPdf;
18
19
20 public class RawImageDemo {
21
22 public static void Main() {
23 Console.WriteLine("libhpdf-" + HPdfDoc.HPdfGetVersion());
24
25 byte[] raw_image_data = new byte[] {
26 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xfc,
27 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xf0,
28 0xf3, 0xf3, 0xff, 0xe0, 0xf3, 0xf3, 0xff, 0xc0,
29 0xf3, 0xf3, 0xff, 0x80, 0xf3, 0x33, 0xff, 0x00,
30 0xf3, 0x33, 0xfe, 0x00, 0xf3, 0x33, 0xfc, 0x00,
31 0xf8, 0x07, 0xf8, 0x00, 0xf8, 0x07, 0xf0, 0x00,
32 0xfc, 0xcf, 0xe0, 0x00, 0xfc, 0xcf, 0xc0, 0x00,
33 0xff, 0xff, 0x80, 0x00, 0xff, 0xff, 0x00, 0x00,
34 0xff, 0xfe, 0x00, 0x00, 0xff, 0xfc, 0x00, 0x00,
35 0xff, 0xf8, 0x0f, 0xe0, 0xff, 0xf0, 0x0f, 0xe0,
36 0xff, 0xe0, 0x0c, 0x30, 0xff, 0xc0, 0x0c, 0x30,
37 0xff, 0x80, 0x0f, 0xe0, 0xff, 0x00, 0x0f, 0xe0,
38 0xfe, 0x00, 0x0c, 0x30, 0xfc, 0x00, 0x0c, 0x30,
39 0xf8, 0x00, 0x0f, 0xe0, 0xf0, 0x00, 0x0f, 0xe0,
40 0xe0, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00,
41 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
42 };
43
44 try {
45 HPdfDoc pdf = new HPdfDoc();
46
47 pdf.SetCompressionMode(HPdfDoc.HPDF_COMP_ALL);
48
49 /* create default-font */
50 HPdfFont font = pdf.GetFont("Helvetica", null);
51
52 /* add a new page object. */
53 HPdfPage page = pdf.AddPage();
54
55 page.SetWidth(172);
56 page.SetHeight(80);
57
58 page.BeginText();
59 page.SetFontAndSize(font, 20);
60 page.MoveTextPos(220, page.GetHeight() - 70);
61 page.ShowText("RawImageDemo");
62 page.EndText();
63
64 /* load RGB raw-image file. */
65 HPdfImage image = pdf.LoadRawImageFromFile("demo\\rawimage\\32_32_rgb.dat",
66 32, 32, HPdfColorSpace.HPDF_CS_DEVICE_RGB);
67
68 float x = 20;
69 float y = 20;
70
71 /* Draw image to the canvas. (normal-mode with actual size.)*/
72 page.DrawImage(image, x, y, 32, 32);
73
74 /* load GrayScale raw-image file. */
75 image = pdf.LoadRawImageFromFile("demo\\rawimage\\32_32_gray.dat",
76 32, 32, HPdfColorSpace.HPDF_CS_DEVICE_GRAY);
77
78 x = 70;
79 y = 20;
80
81 /* Draw image to the canvas. (normal-mode with actual size.)*/
82 page.DrawImage(image, x, y, 32, 32);
83
84 /* load GrayScale raw-image (1bit) file from memory. */
85 image = pdf.LoadRawImageFromMem(raw_image_data, 32, 32,
86 HPdfColorSpace.HPDF_CS_DEVICE_GRAY, 1);
87
88 x = 120;
89 y = 20;
90
91 /* Draw image to the canvas. (normal-mode with actual size.)*/
92 page.DrawImage(image, x, y, 32, 32);
93
94 /* save the document to a file */
95 pdf.SaveToFile("RawImageDemo.pdf");
96
97 } catch (Exception e) {
98 Console.Error.WriteLine(e.Message);
99 }
100 }
101 }
102
103
104