'''' This code is part of Document Solutions for Imaging demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.DrawingImportsSystem.Collections.GenericImportsSystem.LinqImportsSystem.NumericsImportsGrapeCity.Documents.DrawingImportsGrapeCity.Documents.TextImportsGrapeCity.Documents.ImagingImports GCTEXT = GrapeCity.Documents.TextImports GCDRAW = GrapeCity.Documents.Drawing '' This sample shows how to extract frames from a TIFF image,'' and how to read them as GcBitmap instances.PublicClassExtractFramesFunctionGenerateImage(ByVal pixelSize AsSize,ByVal dpi AsSingle,ByVal opaque AsBoolean,OptionalByVal sampleParams AsString() = Nothing) AsGcBitmap '' Create the resulting image:Dim 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:Dim imagePath = Path.Combine("Resources", "ImagesBis", "BmpWriteTiff3.tiff") '' List to hold bitmaps for the TIFF frames:Dim frameBmps(0) AsGcBitmap '' Read all frames from the TIFF file:Using stm = NewFileStream(imagePath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, FileOptions.RandomAccess)Using tr = NewGcTiffReader(stm)ReDim frameBmps(tr.Frames.Count - 1)For i = 0To tr.Frames.Count - 1 frameBmps(i) = tr.Frames(i).ToGcBitmap() frameBmps(i).Opaque = opaqueNextEndUsingEndUsing '' Resize and render the frames' bitmaps into the resulting image:Dim w = pixelSize.Width / 2Dim h = pixelSize.Height / 2If frameBmps.Length > 0ThenUsing tbmp = frameBmps(0).Resize(w, h) bmp.BitBlt(tbmp, 0, 0)EndUsingEndIfIf frameBmps.Length > 1ThenUsing tbmp = frameBmps(1).Resize(w, h) bmp.BitBlt(tbmp, w, 0)EndUsingEndIfIf frameBmps.Length > 2ThenUsing tbmp = frameBmps(2).Resize(w, h) bmp.BitBlt(tbmp, 0, h)EndUsingEndIfIf frameBmps.Length > 3ThenUsing tbmp = frameBmps(3).Resize(w, h) bmp.BitBlt(tbmp, w, h)EndUsingEndIf '' Dispose the frame bitmaps:ForEach tbmp In frameBmps tbmp.Dispose()Next '' Add borders between the quadrants, and captions for each:Using g = bmp.CreateGraphics()Dim foreColor = Color.YellowDim backColor = Color.BlueDim fnt = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FreeMono.ttf"))Dim 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))Dim tf = NewTextFormat() With {.Font = fnt, .FontSize = 18, .ForeColor = foreColor, .BackColor = backColor, .FontBold = True}Dim th = g.MeasureString("QWERTY", tf).HeightIf frameBmps.Length > 0Then g.DrawString(" Frame 0 ", tf, NewPointF(0, h - th + lineh))EndIfIf frameBmps.Length > 1Then g.DrawString(" Frame 1 ", tf, NewPointF(w + lineh, h - th + lineh))EndIfIf frameBmps.Length > 2Then g.DrawString(" Frame 2 ", tf, NewPointF(0, h * 2 + lineh - th + lineh))EndIfIf frameBmps.Length > 3Then g.DrawString(" Frame 3 ", tf, NewPointF(w + lineh, h * 2 + lineh - th + lineh))EndIfEndUsing Return bmpEndFunctionEndClass