//// This code is part of Document Solutions for Imaging demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem.IO;usingSystem.Drawing;usingGrapeCity.Documents.Text;usingGrapeCity.Documents.Imaging;usingGCTEXT = GrapeCity.Documents.Text;usingGCDRAW = GrapeCity.Documents.Drawing; namespaceDsImagingWeb.Demos{// This sample shows how to extract frames from a TIFF image,// and how to read them as GcBitmap instances.publicclassExtractFrames {publicGcBitmapGenerateImage(Size pixelSize, float dpi, bool opaque, string[] sampleParams = null) {// Create the resulting image:var bmp = newGcBitmap(pixelSize.Width, pixelSize.Height, opaque, dpi, dpi); // If there is a possibility that we will not fill some areas of the target bitmap// (as in this case where the number of frames in the TIFF may be less than 4),// we MUST clear the resulting bitmap as GcBitmap ctor does NOT clear the memory// allocated for the pixels (to save time, as initializing large bitmaps may be// very slow): bmp.Clear(); // Sample TIFF image path:var imagePath = Path.Combine("Resources", "ImagesBis", "BmpWriteTiff3.tiff"); // List to hold bitmaps for the TIFF frames:GcBitmap[] frameBmps; // Read all frames from the TIFF file:using (var stm = newFileStream(imagePath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, FileOptions.RandomAccess))using (var tr = newGcTiffReader(stm)) { frameBmps = newGcBitmap[tr.Frames.Count];for (int i = 0; i < tr.Frames.Count; ++i) { frameBmps[i] = tr.Frames[i].ToGcBitmap(); frameBmps[i].Opaque = opaque; } } // Resize and render the frames' bitmaps into the resulting image:int w = pixelSize.Width / 2;int h = pixelSize.Height / 2;if (frameBmps.Length > 0)using (var tbmp = frameBmps[0].Resize(w, h)) bmp.BitBlt(tbmp, 0, 0);if (frameBmps.Length > 1)using (var tbmp = frameBmps[1].Resize(w, h)) bmp.BitBlt(tbmp, w, 0);if (frameBmps.Length > 2)using (var tbmp = frameBmps[2].Resize(w, h)) bmp.BitBlt(tbmp, 0, h);if (frameBmps.Length > 3)using (var tbmp = frameBmps[3].Resize(w, h)) bmp.BitBlt(tbmp, w, h); // Dispose the frame bitmaps:foreach (var tbmp in frameBmps) tbmp.Dispose(); // Add borders between the quadrants, and captions for each:using (var g = bmp.CreateGraphics()) {var foreColor = Color.Yellow;var backColor = Color.Blue;var font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FreeMono.ttf"));var lineh = 2; g.DrawLine(w, 0, w, h * 2, newGCDRAW.Pen(Color.Gray, lineh * 2)); g.DrawLine(0, h, w * 2, h, newGCDRAW.Pen(Color.Gray, lineh * 2));var tf = newTextFormat() { Font = font, FontSize = 18, ForeColor = foreColor, BackColor = backColor, FontBold = true };var th = g.MeasureString("QWERTY", tf).Height;if (frameBmps.Length > 0) g.DrawString(" Frame 0 ", tf, newPointF(0, h - th + lineh));if (frameBmps.Length > 1) g.DrawString(" Frame 1 ", tf, newPointF(w + lineh, h - th + lineh));if (frameBmps.Length > 2) g.DrawString(" Frame 2 ", tf, newPointF(0, h * 2 + lineh - th + lineh));if (frameBmps.Length > 3) g.DrawString(" Frame 3 ", tf, newPointF(w + lineh, h * 2 + lineh - th + lineh)); } return bmp; } }}