/* ----------------------------------------------------------------- */ /// /// GetBitmap /// /// <summary> /// Creates a new instance of the Bitmap class with the specified /// arguments. /// </summary> /// /* ----------------------------------------------------------------- */ public static Bitmap GetBitmap(this RenderOption src, int width, int height) { var dest = new Bitmap(width, height, PixelFormat.Format32bppArgb); src.DrawBackground(e => { using (var gs = Graphics.FromImage(dest)) gs.Clear(e); }); return(dest); }
/* ----------------------------------------------------------------- */ /// /// DrawBackground /// /// <summary> /// Draws the background. /// </summary> /// /* ----------------------------------------------------------------- */ public static void DrawBackground(this RenderOption src, Action <Color> action) { if (src.Background != Color.Transparent) { action(src.Background); } }
/* ----------------------------------------------------------------- */ /// /// Render /// /// <summary> /// Executes the rendering with the specified arguments. /// </summary> /// /* ----------------------------------------------------------------- */ public static void Render(IntPtr core, Graphics dest, Page page, PointF point, SizeF size, RenderOption options) => Load(core, page.Number, hp => { options.DrawBackground(e => dest.Clear(e)); var x = (int)point.X; var y = (int)point.Y; var width = (int)size.Width; var height = (int)size.Height; var degree = GetRotation(page.Delta); var flags = options.GetFlags(); var hdc = dest.GetHdc(); NativeMethods.FPDF_RenderPage(hdc, hp, x, y, width, height, degree, flags); dest.ReleaseHdc(hdc); return(true); });
/* ----------------------------------------------------------------- */ /// /// Render /// /// <summary> /// Executes the rendering with the specified arguments. /// </summary> /// /* ----------------------------------------------------------------- */ public static Image Render(IntPtr core, Page page, SizeF size, RenderOption options) => Load(core, page.Number, hp => { var width = (int)size.Width; var height = (int)size.Height; var degree = GetRotation(page.Delta); var flags = options.GetFlags(); var bpp = 4; var dest = options.GetBitmap(width, height); var data = dest.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, dest.PixelFormat); var hbm = NativeMethods.FPDFBitmap_CreateEx(width, height, bpp, data.Scan0, width * bpp); NativeMethods.FPDF_RenderPageBitmap(hbm, hp, 0, 0, width, height, degree, flags); NativeMethods.FPDFBitmap_Destroy(hbm); dest.UnlockBits(data); return(dest); });
/* ----------------------------------------------------------------- */ /// /// GetFlags /// /// <summary> /// Gets the flags from the specified option. /// </summary> /// /* ----------------------------------------------------------------- */ public static int GetFlags(this RenderOption src) { var dest = RenderFlags.Empty; if (src.Annotation) { dest |= RenderFlags.Annotation; } if (src.Grayscale) { dest |= RenderFlags.Grayscale; } if (src.Print) { dest |= RenderFlags.Printng; } if (!src.AntiAlias) { dest |= RenderFlags.NoSmoothText | RenderFlags.NoSmoothImage | RenderFlags.NoSmoothPath; } return((int)dest); }