''
'' This code is part of Document Solutions for Imaging demos.
'' Copyright (c) MESCIUS inc. All rights reserved.
''
Imports System.IO
Imports System.Drawing
Imports System.Collections.Generic
Imports System.Linq
Imports System.Numerics
Imports GrapeCity.Documents.Drawing
Imports GrapeCity.Documents.Text
Imports GrapeCity.Documents.Imaging
'' This sample takes a color JPEG, converts it to different image types
'' (such as b/w and grayscale) and creates a multi-frame TIFF from those
'' images.
Public Class ImageTypesInTiff
Function GenerateImageStream(
ByVal targetMime As String,
ByVal pixelSize As Size,
ByVal dpi As Single,
ByVal opaque As Boolean,
Optional sampleParams As String() = Nothing) As Stream
If Not targetMime = MimeTypes.TIFF Then
Throw New Exception("This sample only supports TIFF output format.")
End If
Dim pth = Path.Combine("Resources", "Images", "minerva.jpg")
Dim ms = New MemoryStream()
Using tw = New GcTiffWriter(ms),
bmp = New GcBitmap(pth)
'' Using the green channel produces a marginally better result for this photo.
'' For a much better bilevel image produced by dithering, see DitheringInTiff.
Using f = bmp.ToBilevelBitmap(ColorChannel.Green)
tw.AppendFrame(f)
End Using
Using f = bmp.ToGrayscaleBitmap()
tw.AppendFrame(f)
End Using
'' 4bpp allows from 8 to 16 colors, we use max (16)
Using f = bmp.ToIndexed4bppBitmap(16)
tw.AppendFrame(f)
End Using
'' 8bpp allows from 8 to 256 colors, we use max (256)
Using f = bmp.ToIndexed8bppBitmap(256)
tw.AppendFrame(f)
End Using
tw.AppendFrame(bmp)
End Using
ms.Seek(0, SeekOrigin.Begin)
Return ms
End Function
Public ReadOnly Property DefaultMime() As String
Get
Return MimeTypes.TIFF
End Get
End Property
End Class