我正在尝试保存以存档已调整大小的图片,其中包含LoadPicture
。使用以下代码,我加载图像并调整其大小,但我现在明白Me.Image1.Width
将图像调整为image box
控件的大小仅用于显示目的。
如果我使用savepicture()
保存图像,则保存的图像与加载的图像相同。
Private Sub CommandButtonImage_Click()
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.ButtonName = "Submit"
.Title = "Select a image"
.Filters.Add "Image", "*.gif; *.jpg; *.jpeg; *.png", 1
If .Show = -1 Then
' file has been selected
' fit image into image box
Me.Image1.PictureSizeMode = fmPictureSizeModeZoom
' display preview image in an image control
Me.Image1.Picture = LoadPicture(.SelectedItems(1))
' resize image
Me.Image1.Width = 50
Else
' something
End If
End With
End Sub
答案 0 :(得分:2)
<强>解决。强>
根据建议,我使用了ImageMagick(以下内容适用于v7.0.2-4)。
以下代码打开一个对话框窗口以选择图像,调用ImageMagickObject OLE,调整图像大小并将其保存到新文件中:
Private Sub CommandButtonImage_Click()
Dim img
Set img = CreateObject("ImageMagickObject.MagickImage")
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.ButtonName = "Submit"
.Title = "Selezionare un'immagine"
.Filters.Add "Image", "*.gif; *.jpg; *.jpeg; *.png", 1
If .Show = -1 Then
' file has been selected
' fit image into image box
Me.Image1.PictureSizeMode = fmPictureSizeModeZoom
' display preview image in an image control
Me.Image1.Picture = LoadPicture(.SelectedItems(1))
' this will resize the selected image keeping the aspect ratio
' but resizing will be done only to fit into the size given
' ('>' sign) and it will set the image name to 'resized.jpg'
img.Convert .SelectedItems(1), "-resize", "300x300>", "c:\resized.jpg"
Else
' something
End If
End With
End Sub
其他ImageMagick resize options。