各位高手,帮个忙,TIFF图片(5、6张)转换成JPG图片时,永远只能保存第一张,这是怎么回事?

Python018

各位高手,帮个忙,TIFF图片(5、6张)转换成JPG图片时,永远只能保存第一张,这是怎么回事?,第1张

这最近也在收集这方面的资料。以下是其中一些。希望对你有用。

tiff里存的一个图片结束时会有一个偏移量。从那个偏移量再提取下一个图片。

TIFF to JPEG - the Visual Basic Source Code

Requires Victor Image Processing Library for 32-bit Windows v 5 or higher.

Private Sub mnuconvertTIFFtoJPG_Click()

Dim tmpimage As imgdes' Image descriptors

Dim tmp2image As imgdes

Dim rcode As Long

Dim quality As Long

Dim fileinfo As TiffData ' Reserve space for TIFF struct

Dim tif_fname As String

Dim jpg_fname As String

tif_fname = "test.tif"

jpg_fname = "test.jpg"

quality = 75

' Get info on the file we're to load

rcode = tiffinfo(tif_fname, fileinfo)

If (rcode <>NO_ERROR) Then

MsgBox "Cannot find file", 0, "Error encountered!"

Exit Sub

End If

' Allocate space for an image

rcode = allocimage(tmpimage, fileinfo.width, fileinfo.length, fileinfo.vbitcount)

If (rcode <>NO_ERROR) Then

MsgBox "Not enough memory", 0, "Error encountered!"

Exit Sub

End If

' Load image

rcode = loadtif(tif_fname, tmpimage)

If (rcode <>NO_ERROR) Then

freeimage tmpimage ' Free image on error

MsgBox "Cannot load file", 0, "Error encountered!"

Exit Sub

End If

If (fileinfo.vbitcount = 1) Then ' If we loaded a 1-bit image, convert to 8-bit grayscale

' because jpeg only supports 8-bit grayscale or 24-bit color images

rcode = allocimage(tmp2image, fileinfo.width, fileinfo.length, 8)

If (rcode = NO_ERROR) Then

rcode = convert1bitto8bit(tmpimage, tmp2image)

freeimage tmpimage ' Replace 1-bit image with grayscale image

copyimgdes tmp2image, tmpimage

End If

End If

If (fileinfo.vbitcount = 16) Then ' If we loaded a 16-bit grayscale image, convert to 8-bit grayscale

' because jpeg only supports 8-bit grayscale

rcode = allocimage(tmp2image, filedat.width, filedat.length, 8)

If (rcode = NO_ERROR) Then

rcode = convertgray16to8(tmpimage, tmp2image)

freeimage tmpimage ' Replace 16-bit grayscale image with 8-bit grayscale image

copyimgdes tmp2image, tmpimage

End If

End If

' Save image

rcode = savejpg(jpg_fname, tmpimage, quality)

freeimage tmpimage

End Sub

........... Add these defines and declarations to your Global module ...........

' Image descriptor

Type imgdes

ibuff As Long

stx As Long

sty As Long

endx As Long

endy As Long

buffwidth As Long

palette As Long

colors As Long

imgtype As Long

bmh As Long

hBitmap As Long

End Type

' TIFF file info

Type TiffData

ByteOrder As Long

width As Long

length As Long

BitsPSample As Long

comp As Long

SamplesPPixel As Long

PhotoInt As Long

PlanarCfg As Long

vbitcount As Long

End Type

Declare Function tiffinfo Lib "VIC32.DLL" (ByVal Fname As String, tdat As TiffData) As Long

Declare Function loadtif Lib "VIC32.DLL" (ByVal Fname As String, desimg As imgdes) As Long

Declare Function convertgray16to8 Lib "VIC32.DLL" (srcimg As imgdes, resimg As imgdes) As Long

Declare Function allocimage Lib "VIC32.DLL" (image As imgdes, ByVal wid As Long, ByVal leng As Long, ByVal BPPixel As Long) As Long

Declare Sub freeimage Lib "VIC32.DLL" (image As imgdes)

Declare Function convert1bitto8bit Lib "VIC32.DLL" (srcimg As imgdes, desimg As imgdes) As Long

Declare Sub copyimgdes Lib "VIC32.DLL" (srcimg As imgdes, desimg As imgdes)

Declare Function savejpg Lib "VIC32.DLL" (ByVal Fname As String, srcimg As imgdes, ByVal quality As Long) As Long

1、首先需要点击主菜单栏里的“File”。

2、其次可以发现有“ExportGraph”的子目录,点击之后选择“OpenDialop...”。

3、然后改成tiff(高保真),或者jpg格式,选择对文件名称“filename”进行更改,同时更改保存路径。

4、最后点击OK即可。