加了個 ChangeFileDPI 副程式
及改良 Command2_Click()
不過你那個存檔方式還是只能存成 BMP格式 (只是改個副檔名成 .jpg實際上是掩耳盜鈴 ...)
語法:
Private Sub Command2_Click()
Dim i As Integer
For i = Image1.LBound To Image1.UBound
Image1(i).Picture = LoadPicture()
Next
Picture1.Refresh
End Sub
Private Sub Command3_Click()
Dim i As Integer, X As Long, Y As Long
Picture1.AutoRedraw = True
Picture1.Width = Image1(0).Width * 4
Picture1.Height = Image1(0).Height * 2
X = 0: Y = 0
For i = 0 To 7
If Image1(i).Picture <> 0 Then
Picture1.PaintPicture Image1(i).Picture, X, Y, Image1(i).Width, Image1(i).Height
End If
X = X + Image1(0).Width
If i = 3 Then
X = 0
Y = Y + Image1(0).Height
End If
Next
With CommonDialog2
.FileName = ""
.Filter = "JPEG files (*.jpg) |*.jpg|BMP files (*.bmp) |*.bmp"
.ShowSave
If .FileName = "" Then Exit Sub
SavePicture Picture1.Image, .FileName '存檔成 BMP
ChangeFileDPI .FileName '改成適當DPI
End With
End Sub
'改成適當DPI
Private Sub ChangeFileDPI(sFileName As String, Optional iDPI = 300#) '預設 DPI為 300
Dim lFileID As Long
Dim byteData() As Byte
Dim sDPI As String, sMode As String
Dim bHiByte As Byte, bLoByte As Byte
sMode = LCase(Right(sFileName, 3)) '得到最右邊的副檔名並統一轉成小寫
If sMode = "bmp" Then iDPI = iDPI * 39.37 '如果是 BMP檔需換算
sDPI = Right("0000" & Hex(iDPI), 4) '將數字轉成四位形式的十六進位字串
bHiByte = CByte("&H" & Left(sDPI, 2)) '取左邊兩個
bLoByte = CByte("&H" & Right(sDPI, 2)) '取右邊兩個
lFileID = FreeFile '向系統取得一個尚未被使用的檔案代碼
'**改變 JPEG圖檔 解析度**
If sMode = "jpg" Then
ReDim byteData(17) As Byte
'*取出適當的File Header資訊
Open sFileName For Binary Access Read As #lFileID
Get #lFileID, , byteData()
Close #lFileID
'換上所需的 DPI資訊
byteData(14) = bHiByte
byteData(15) = bLoByte
byteData(16) = bHiByte
byteData(17) = bLoByte
'**改變 BMP圖檔 解析度**
ElseIf sMode = "bmp" Then
ReDim byteData(&H2B) As Byte
Open sFileName For Binary Access Read As #lFileID
Get #lFileID, , byteData()
Close #lFileID
byteData(&H26) = bLoByte
byteData(&H27) = bHiByte
byteData(&H2A) = bLoByte
byteData(&H2B) = bHiByte
Else
Exit Sub
End If
'*存回
Open sFileName For Binary Access Write As #lFileID
Put #lFileID, , byteData()
Close #lFileID
End Sub
其實 DPI應該根據 像素來算出適當的值
而不是固定用 300等固定值