VB.Net Tutorial/2D Graphics/Tiff

Материал из VB Эксперт
Перейти к: навигация, поиск

Create Tiff file

Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Imaging
public class MainClass
   public Shared Sub Main
        Dim bm As New Bitmap(256, 256)
        Dim gr As Graphics = Graphics.FromImage(bm)
        gr.Clear(Color.White)
        gr.DrawEllipse(Pens.Red, 0, 0, bm.Width - 1, bm.Height - 1)
        gr.DrawLine(Pens.Green, 0, 0, bm.Width - 1, bm.Height - 1)
        gr.DrawLine(Pens.Blue, bm.Width - 1, 0, 0, bm.Height - 1)
        bm.Save("test.jpg", ImageFormat.Tiff)
   End Sub
End class

Tiff Encoder

Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
Imports System.Data
Imports System.Drawing.Imaging
public class MainClass
   public Shared Sub Main
        Dim imgCodecInfo As ImageCodecInfo = Nothing
        Dim encoder As Encoder = Nothing
        Dim encoderParam As EncoderParameter = Nothing
        Dim encoderParams As New EncoderParameters(3)
        Dim curBitmap As New Bitmap("yourfile.jpg")
        Dim mimeType As String = "image/tiff"
        Dim encoders() As ImageCodecInfo
        encoders = ImageCodecInfo.GetImageEncoders()
        Dim i As Integer
        While i < encoders.Length
            If encoders(i).MimeType = mimeType Then
                imgCodecInfo = encoders(i)
            End If
        End While " Set color depth to 24 pixels
        encoder = encoder.ColorDepth
        encoderParam = New EncoderParameter(encoder, CLng(EncoderValue.rupressionLZW))
        encoderParams.Param(0) = encoderParam
        encoder = encoder.rupression
        encoderParam = New EncoderParameter(encoder, CLng(EncoderValue.rupressionLZW))
        encoderParams.Param(1) = encoderParam
        encoder = encoder.Transformation
        encoderParam = New EncoderParameter(encoder, CLng(EncoderValue.TransformRotate180))
        encoderParams.Param(2) = encoderParam
        curBitmap.Save("newFile.tif", imgCodecInfo, encoderParams)
        curBitmap.Dispose()
   End Sub
End class