VB.Net Tutorial/2D Graphics/Tiff — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 12:55, 26 мая 2010
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