Tif转换到Jpg问题

MeXP 2002-05-15 03:02:02
为什么采用采用vic32.dll将Tif转换到Jpg,黑白反色,也就是白纸成了黑纸,黑字却成了白字
有谁有这样的代码
同一张图片用acdsee3转换没有问题,代码错在何处?
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
...全文
143 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
johnsonrao 2002-07-20
  • 打赏
  • 举报
回复
帮你提一提!
zyl910 2002-05-15
  • 打赏
  • 举报
回复
看他们的文件格式:http://www.csdn.net/Dev/Format/#图形文件
MeXP 2002-05-15
  • 打赏
  • 举报
回复
问题是不是太难了,我只想听听可能的原因
MeXP 2002-05-15
  • 打赏
  • 举报
回复
up

24,923

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Apache
社区管理员
  • Apache
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧