2 * << Haru Free PDF Library 2.0.5 >> -- RawImageDemo.cs
4 * Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
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.
20 public class RawImageDemo {
22 public static void Main() {
23 Console.WriteLine("libhpdf-" + HPdfDoc.HPdfGetVersion());
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
45 HPdfDoc pdf = new HPdfDoc();
47 pdf.SetCompressionMode(HPdfDoc.HPDF_COMP_ALL);
49 /* create default-font */
50 HPdfFont font = pdf.GetFont("Helvetica", null);
52 /* add a new page object. */
53 HPdfPage page = pdf.AddPage();
59 page.SetFontAndSize(font, 20);
60 page.MoveTextPos(220, page.GetHeight() - 70);
61 page.ShowText("RawImageDemo");
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);
71 /* Draw image to the canvas. (normal-mode with actual size.)*/
72 page.DrawImage(image, x, y, 32, 32);
74 /* load GrayScale raw-image file. */
75 image = pdf.LoadRawImageFromFile("demo\\rawimage\\32_32_gray.dat",
76 32, 32, HPdfColorSpace.HPDF_CS_DEVICE_GRAY);
81 /* Draw image to the canvas. (normal-mode with actual size.)*/
82 page.DrawImage(image, x, y, 32, 32);
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);
91 /* Draw image to the canvas. (normal-mode with actual size.)*/
92 page.DrawImage(image, x, y, 32, 32);
94 /* save the document to a file */
95 pdf.SaveToFile("RawImageDemo.pdf");
97 } catch (Exception e) {
98 Console.Error.WriteLine(e.Message);