A. vb中将bmp格式的图片转换为JPG格式。要代码,最好越简单越好
下面是源代码:
添加picturebox,commandbutton
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
http://tieba..com/f?ct=335675392&tn=PostBrowser&sc=3183913151&z=314561243&pn=0&rn=50&lm=0&word=vb#3183913151 http://tieba..com/f?kz=333370629http://download.csdn.net/source/1041194
B. VB编程转换图片格式
这类似功能一般要借助外部控件来实现的,商用软件的文件存储格式一般不会公开的,所以很难自己读写来转换。不过他们一般提供开发的接口控件,你尝试找一下!
C. VB将图片保存为jpg格式
我正在用呀,没有任何问题!你的设置可能有问题!
Private Sub Command4_Click()
If Combo1.Text = "" Then
MsgBox "请您输入转换格式!!", 48, "提示信息"
Exit Sub
ElseIf Text2.Text = "" Or Text3.Text = "" Then
MsgBox "请选择转换前和转换后的文件路径!!", 48, "提示信息"
Exit Sub
Else
Me.MousePointer = 11
Command4.Enabled = False
Dim i, j, w, h, w1, h1, k As Integer
w = Picture1.Width
h = Picture1.Height
w1 = w / 15
h1 = h / 15
Picture2.Width = w
Picture2.Height = h
Picture1.Scale (0, 0)-(w1, h1)
Picture2.Scale (0, 0)-(w1, h1)
For i = 1 To w1
For j = 1 To h1
Picture2.PSet (i, j), Picture1.Point(i, j)
Next j
Next i
Picture2.Picture = Picture2.Image
SavePicture Picture2.Image, Text3.Text & "." & Mid(Combo1.Text, 3, Len(Combo1.Text) - 1)
MsgBox "格式转换成功完成!!", 64, "提示信息"
Command4.Enabled = True
Me.MousePointer = 0
End If
End Sub
Private Sub Command2_Click()
On Error GoTo x
DHK1.Filter = "所有文件(*.*)|*.*"
DHK1.ShowOpen
Text2.Text = DHK1.FileName
Image1.Picture = LoadPicture(Text2.Text)
Picture1.Picture = Image1.Picture
Exit Sub
x:
MsgBox "无效图片!", 64, "提示信息"
End Sub
Private Sub Command3_Click()
DHK1.Filter = "所有文件(*.*)|*.*"
DHK1.ShowSave
Text3.Text = DHK1.FileName
End Sub
DHK1是CommonDialog控件
D. 如何将vb中bmp格式的图片转换为JPG格式
打开图片,选择另存为,在保存的格式中选择jpg就可以了
E. 如何将vb中bmp格式的图片转换为JPG格式
首先我们使用Windows自带的照片查看器打开需要转换的BMP格式图片。
然后在菜单栏里找到“打开”选项,然后选择使用“画图”来打开这张图片。
在画图工具里打开这个图片之后,点击如图所示的白色三角符号,然后讲鼠标移动到“另存为”。
然后在“另存为”隐藏的菜单里单击“JPEG图片”,在这里系统已经自动为图片命名了,后缀名已经是.jpg了,单击保存即可保存到桌面。
F. vb怎样修改位图图片的格式
Dim OldName, NewName
OldName = "d:\s.bmp": NewName = "d:\s.jpg" ' 定义文件名。
Name OldName As NewName ' 更改文件名。
G. 如何实现VB图片转换
1、添加控件ImageList用来存储图片。
2、添加控件Command1,Command2。
3、添加控件Image来显示图片。
Private Sub Command1_Click()
Image1.Picture = ImageList1.ListImages(1).Picture
End Sub
Private Sub Command2_Click()
Image1.Picture = ImageList1.ListImages(2).Picture
End Sub
H. vb 图片如何转换成字符
为什么要保存为字符,读取文件时可使用二进制方式保存到字节数组中
I. VB,怎样做图片格式转换
需要一个图像解码器(dll)
J. vb如何改图片
方法如下:
1、读取该图片;
2、使用PaintPicture方法缩放绘制图片;
3、保存PictureBox中的图片。
注意:VB的SavePicture只能保存BMP,想保存为其他格式,只能自己根据文件格式写,或者找控件。