VB 如何压缩一张.bmp图片? 25
并不是转换压缩成.JPG图片。就像我们用RAR压缩工具一样就行,原理不必一样,只要能压缩即可!比如图片大小为1.2M压缩后为860K,还要能解压后生成原来的1.2M~谢谢...
并不是转换压缩成.JPG图片。就像我们用RAR压缩工具一样就行,原理不必一样 ,只要能压缩即可!比如图片大小为1.2M 压缩后为860K ,还要能解压后生成原来的1.2M ~谢谢~ 最好写个简单的源码 我QQ271072330
展开
5个回答
展开全部
好象很难的样子,我不会,学习!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
需要在窗体上画以下控件:
Picture1
Picture2
Picture3
CommonDialog1
CommonDialog2
CommonDialog3
command1
Command2
command3
问题提供的条件不够充分,首先是否允许更换图片尺寸,另外是可以保存成其他格式。
如果不允许改变尺寸也不允许更改类型,那么只有降低bmp的位数来降低尺寸,但同时会导致图片的质量下降。
百度吧里有一篇文章是一段源码,你可以看一下:http://tieba.baidu.com/f?kz=88393068
同时如果需要更多关于图片类型转换的操作,可以去csdn上找一些,十分的多。
Picture1
Picture2
Picture3
CommonDialog1
CommonDialog2
CommonDialog3
command1
Command2
command3
问题提供的条件不够充分,首先是否允许更换图片尺寸,另外是可以保存成其他格式。
如果不允许改变尺寸也不允许更改类型,那么只有降低bmp的位数来降低尺寸,但同时会导致图片的质量下降。
百度吧里有一篇文章是一段源码,你可以看一下:http://tieba.baidu.com/f?kz=88393068
同时如果需要更多关于图片类型转换的操作,可以去csdn上找一些,十分的多。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
要实现压缩功能,只有用第3方控件,或者调用压缩程序命令行
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
位图可以采用RLE算法压缩,RLE是一种无损压缩算法,不过压缩比不会有JPEG高
你去找一下相关的RLE压缩位图的算法吧
你去找一下相关的RLE压缩位图的算法吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Option Explicit
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
Private Type GdiplusStartupInput
GdiplusVersion As Long
DebugEventCallback As Long
SuppressBackgroundThread As Long
SuppressExternalCodecs As Long
End Type
Private Type EncoderParameter
GUID As GUID
NumberOfValues As Long
type As Long
Value As Long
End Type
Private Type EncoderParameters
Count As Long
Parameter As EncoderParameter
End Type
Private Declare Function GdiplusStartup Lib "GDIPlus" (token As Long, inputbuf As GdiplusStartupInput, ByVal outputbuf As Long) As Long
Private Declare Function GdiplusShutdown Lib "GDIPlus" (ByVal token As Long) As Long
Private Declare Function GdipCreateBitmapFromHBITMAP Lib "GDIPlus" (ByVal hbm As Long, ByVal hpal As Long, Bitmap As Long) As Long
Private Declare Function GdipDisposeImage Lib "GDIPlus" (ByVal Image As Long) As Long
Private Declare Function GdipSaveImageToFile Lib "GDIPlus" (ByVal Image As Long, ByVal filename As Long, clsidEncoder As GUID, encoderParams As Any) As Long
Private Declare Function CLSIDFromString Lib "ole32" (ByVal str As Long, id As GUID) As Long
Private Declare Function GdipCreateBitmapFromFile Lib "GDIPlus" (ByVal filename As Long, Bitmap As Long) As Long
Private Sub Command1_Click()
Dim ret As Boolean
Picture1.Picture = LoadPicture("C:\a.bmp") '打开要压缩的图片
ret = PictureBoxSaveJPG(Picture1, "C:\b.jpg") '保存压缩后的图片
If ret = False Then
MsgBox "保存失败"
End If
End Sub
Private Function PictureBoxSaveJPG(ByVal pict As StdPicture, ByVal filename As String, Optional ByVal quality As Byte = 80) As Boolean
Dim tSI As GdiplusStartupInput
Dim lRes As Long
Dim lGDIP As Long
Dim lBitmap As Long
'初始化 GDI+
tSI.GdiplusVersion = 1
lRes = GdiplusStartup(lGDIP, tSI, 0)
If lRes = 0 Then
'从句柄创建 GDI+ 图像
lRes = GdipCreateBitmapFromHBITMAP(pict.Handle, 0, lBitmap)
If lRes = 0 Then
Dim tJpgEncoder As GUID
Dim tParams As EncoderParameters
'初始化解码器的GUID标识
CLSIDFromString StrPtr("{557CF401-1A04-11D3-9A73-0000F81EF32E}"), tJpgEncoder
'设置解码器参数
tParams.Count = 1
With tParams.Parameter ' Quality
'得到Quality参数的GUID标识
CLSIDFromString StrPtr("{1D5BE4B5-FA4A-452D-9CDD-5DB35105E7EB}"), .GUID
.NumberOfValues = 1
.type = 4
.Value = VarPtr(quality)
End With
'保存图像
lRes = GdipSaveImageToFile(lBitmap, StrPtr(filename), tJpgEncoder, tParams)
'销毁GDI+图像
GdipDisposeImage lBitmap
End If
'销毁 GDI+
GdiplusShutdown lGDIP
End If
If lRes Then
PictureBoxSaveJPG = False
Else
PictureBoxSaveJPG = True
End If
End Function
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
Private Type GdiplusStartupInput
GdiplusVersion As Long
DebugEventCallback As Long
SuppressBackgroundThread As Long
SuppressExternalCodecs As Long
End Type
Private Type EncoderParameter
GUID As GUID
NumberOfValues As Long
type As Long
Value As Long
End Type
Private Type EncoderParameters
Count As Long
Parameter As EncoderParameter
End Type
Private Declare Function GdiplusStartup Lib "GDIPlus" (token As Long, inputbuf As GdiplusStartupInput, ByVal outputbuf As Long) As Long
Private Declare Function GdiplusShutdown Lib "GDIPlus" (ByVal token As Long) As Long
Private Declare Function GdipCreateBitmapFromHBITMAP Lib "GDIPlus" (ByVal hbm As Long, ByVal hpal As Long, Bitmap As Long) As Long
Private Declare Function GdipDisposeImage Lib "GDIPlus" (ByVal Image As Long) As Long
Private Declare Function GdipSaveImageToFile Lib "GDIPlus" (ByVal Image As Long, ByVal filename As Long, clsidEncoder As GUID, encoderParams As Any) As Long
Private Declare Function CLSIDFromString Lib "ole32" (ByVal str As Long, id As GUID) As Long
Private Declare Function GdipCreateBitmapFromFile Lib "GDIPlus" (ByVal filename As Long, Bitmap As Long) As Long
Private Sub Command1_Click()
Dim ret As Boolean
Picture1.Picture = LoadPicture("C:\a.bmp") '打开要压缩的图片
ret = PictureBoxSaveJPG(Picture1, "C:\b.jpg") '保存压缩后的图片
If ret = False Then
MsgBox "保存失败"
End If
End Sub
Private Function PictureBoxSaveJPG(ByVal pict As StdPicture, ByVal filename As String, Optional ByVal quality As Byte = 80) As Boolean
Dim tSI As GdiplusStartupInput
Dim lRes As Long
Dim lGDIP As Long
Dim lBitmap As Long
'初始化 GDI+
tSI.GdiplusVersion = 1
lRes = GdiplusStartup(lGDIP, tSI, 0)
If lRes = 0 Then
'从句柄创建 GDI+ 图像
lRes = GdipCreateBitmapFromHBITMAP(pict.Handle, 0, lBitmap)
If lRes = 0 Then
Dim tJpgEncoder As GUID
Dim tParams As EncoderParameters
'初始化解码器的GUID标识
CLSIDFromString StrPtr("{557CF401-1A04-11D3-9A73-0000F81EF32E}"), tJpgEncoder
'设置解码器参数
tParams.Count = 1
With tParams.Parameter ' Quality
'得到Quality参数的GUID标识
CLSIDFromString StrPtr("{1D5BE4B5-FA4A-452D-9CDD-5DB35105E7EB}"), .GUID
.NumberOfValues = 1
.type = 4
.Value = VarPtr(quality)
End With
'保存图像
lRes = GdipSaveImageToFile(lBitmap, StrPtr(filename), tJpgEncoder, tParams)
'销毁GDI+图像
GdipDisposeImage lBitmap
End If
'销毁 GDI+
GdiplusShutdown lGDIP
End If
If lRes Then
PictureBoxSaveJPG = False
Else
PictureBoxSaveJPG = True
End If
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询