如何将bmp格式的图片压缩转换成jpg或gif格式的图片

yingmu 2004-09-12 12:22:33
在pb中,用摄像头带的ocx只能将拍到的东东保存成bmp格式的图片,但是bmp占空间太大了,有没有什么函数或是控件能将bmp格式的图片压缩转换成jgp格式的图片?先谢了各位。
...全文
417 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
yingmu 2004-10-16
  • 打赏
  • 举报
回复
还没试(偶的电脑坏掉了 *_*! ),先谢谢各位。结贴先。
gcg_cumt 2004-10-13
  • 打赏
  • 举报
回复
使用GDI+不可以吗?给你个参考:

Saving images to JPG using GDI+

This function saves a StdPicture object to a file with JPG format using the GDI+ encoder. Just call the function passing the image object, the filename and, optionally, the image quality (from 1 to 100) .

' ----==== API Declarations ====----

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, _
Optional ByVal outputbuf As Long = 0) 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

' ----==== SaveJPG ====----

Public Sub SaveJPG( _
ByVal pict As StdPicture, _
ByVal filename As String, _
Optional ByVal quality As Byte = 80)
Dim tSI As GdiplusStartupInput
Dim lRes As Long
Dim lGDIP As Long
Dim lBitmap As Long

' Initialize GDI+
tSI.GdiplusVersion = 1
lRes = GdiplusStartup(lGDIP, tSI)

If lRes = 0 Then

' Create the GDI+ bitmap
' from the image handle
lRes = GdipCreateBitmapFromHBITMAP(pict.Handle, 0, lBitmap)

If lRes = 0 Then
Dim tJpgEncoder As GUID
Dim tParams As EncoderParameters

' Initialize the encoder GUID
CLSIDFromString StrPtr("{557CF401-1A04-11D3-9A73-0000F81EF32E}"), _
tJpgEncoder

' Initialize the encoder parameters
tParams.Count = 1
With tParams.Parameter ' Quality
' Set the Quality GUID
CLSIDFromString StrPtr("{1D5BE4B5-FA4A-452D-9CDD-5DB35105E7EB}"), .GUID
.NumberOfValues = 1
.type = 4
.Value = VarPtr(Quality)
End With

' Save the image
lRes = GdipSaveImageToFile( _
lBitmap, _
StrPtr(Filename), _
tJpgEncoder, _
tParams)

' Destroy the bitmap
GdipDisposeImage lBitmap

End If

' Shutdown GDI+
GdiplusShutdown lGDIP

End If

If lRes Then
Err.Raise 5, , "Cannot save the image. GDI+ Error:" & lRes
End If

End Sub
纸飞机2017 2004-10-12
  • 打赏
  • 举报
回复
Graphics::TBitmap* Bitmap = new Graphics::TBitmap;
TJPEGImage* Jpeg = new TJPEGImage;
Bitmap->LoadFromFile(BmpPath);
Jpeg->Assign(Bitmap);
Jpeg->SaveToFile(JpgPath);
delete Bitmap;
delete Jpeg;
纸飞机2017 2004-10-12
  • 打赏
  • 举报
回复
建议用C++ BUILDER写个DLL实现这功能,很简单
不建议使用API函数,太麻烦
tongyi226 2004-10-12
  • 打赏
  • 举报
回复
关注
yingmu 2004-10-12
  • 打赏
  • 举报
回复
有OCX,但是它提供的函数只能把拍到的图片存为BMP格式的,这样文件太大了,我想要一个函数或是控件,能把保存下来的BMP文件压缩转化成JPG或是其他比较小的文件格式。
菜鸟先飞888 2004-09-28
  • 打赏
  • 举报
回复
请问你是用什么那款摄像头,有OCX吗?
yingmu 2004-09-13
  • 打赏
  • 举报
回复
?!为什么没人理我?都没做过吗?我从网上看到有这样的软件,那肯定有相关的dll或是ocx了应该?
yingmu 2004-09-12
  • 打赏
  • 举报
回复
我的qq是79110233,也可以到qq上找我,谢谢。。

680

社区成员

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

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