[VB]BMP转JPG

 代码如下: Option Explicit' Image descriptorType imgdesibuff As Longstx As Longsty As Longendx As Longendy As Longbuffwidth As Longpalette As Longcolors As Longimgtype As Longbmh As LonghBitmap As L...
摘要由CSDN通过智能技术生成
 代码如下:

Option Explicit
' 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
Type BITMAPINFOHEADER
biSize As Long
biWidth As Long
biHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biSizeImage As Long
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Long
biClrImportant As Long
End Type
Declare Function bmpinfo Lib "VIC32.DLL" (ByVal Fname As String, bdat As BITMAPINFOHEADER) 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 Function loadbmp Lib "VIC32.DLL" (ByVal Fname As String, desimg As imgdes) 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

''''''''''''********************************?°????:
Private Sub Command1_Click()
Dim tmpimage As imgdes ' Image descriptors
Dim tmp2image As imgdes
Dim rcode As Long
Dim quality As Long
Dim vbitcount As Long
Dim bdat As BITMAPINFOHEADER ' Reserve space for
struct
Dim bmp_fname As String
Dim jpg_fname As String
bmp_fname = "test.bmp"
jpg_fname = "test.jpg"
quality = 75
' Get info on the file we're to load
rcode = bmpinfo(bmp_fname, bdat)
If (rcode <> NO_ERROR) Then
MsgBox "Cannot find file", 0, "Error encountered!"
Exit Sub
End If
vbitcount = bdat.biBitCount
If (vbitcount >= 16) Then '; 16-, 24-, or 32-bit image is loaded into 24-bit buffer
vbitcount = 24
End If
' Allocate space for an image
rcode = allocimage(tmpimage, bdat.biWidth, bdat.biHeight, vbitcount)
If (rcode <> NO_ERROR) Then
MsgBox "Not enough memory", 0, "Error encountered!"
Exit Sub
End If
Load image
rcode = loadbmp(bmp_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 (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, bdat.biWidth, bdat.biHeight, 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
' Save image
rcode = savejpg(jpg_fname, tmpimage, quality)
freeimage tmpimage
End Sub

摘自:网络整理

VB相关


vbline的用法[]

画图工具的VB实现

VB 一个获得自己外网 IP 地址的程序代码

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值