ImageTypesInTiff.vb
''
'' このコードは、DioDocs for Imaging のサンプルの一部として提供されています。
'' © 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
'' このサンプルでは、カラー JPEG 画像を白黒やグレースケールなどの
'' 異なる画像形式に変換し、それらの画像からマルチフレーム TIFF を作成する方法を示します。
Public Class ImageTypesInTiff
Function GenerateImageStream(
ByVal targetMime As String,
ByVal pixelSize As Size,
ByVal dpi As Single,
ByVal opaque As Boolean,
ByVal 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)
'' この写真では、グリーンチャネルを使用するとわずかに良い結果が得られます。
'' ディザリングによって生成される、より高品質な2値画像については、DitheringInTiffを参照してください。
Using f = bmp.ToBilevelBitmap(ColorChannel.Green)
tw.AppendFrame(f)
End Using
Using f = bmp.ToGrayscaleBitmap()
tw.AppendFrame(f)
End Using
'' 4bppでは8〜16色を使用できます。ここでは最大値(16)を使用します。
Using f = bmp.ToIndexed4bppBitmap(16)
tw.AppendFrame(f)
End Using
'' 8bppでは8〜256色を使用できます。ここでは最大値(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