有的时候,我们需要对图像进行处理,比如缩放,裁剪等等。了解图片的像素是非常重要的。
很多图片显示软件都能直接查看图片的像素,甚至直接在操作系统也能直接显示像素。那么在Access中如果用VBA查看图片像素呢?
效果图:
详细源码:
Private Sub cmdGetPicture_Click()
On Error Resume Next
Dim i As Integer
With FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = True
.Filters.Clear
If .Show = True Then
Me.lstImageSize.RowSource = ""
For i = 1 To .SelectedItems.Count
Me.Image1.Picture = .SelectedItems(i)
If Err = 2114 Then
MsgBox .SelectedItems(i) & "出错,可能是因为以下原因:" & vbCr & vbCr & _
"不是图片文件" & vbCr & "图片太大", vbCritical
End If
If Err = 0 Then
Me.lstImageSize.AddItem .SelectedItems(i) & ";" & _
Round(Me.Image1.ImageWidth / 15) & _
" x " & _
Round(Me.Image1.ImageHeight / 15) & _
" 像素"
Else
Err = 0
End If
Next
End If
End With
End Sub