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,想保存為其他格式,只能自己根據文件格式寫,或者找控制項。