excelvba。将调整大小的图像保存到文件
我正试图保存到文件中,以excelvba。将调整大小的图像保存到文件,excel,vba,Excel,Vba,我正试图保存到文件中,以LoadPicture加载一个已调整大小的图像。使用以下代码,我加载图像并调整其大小,但我现在了解到,Me.Image1.Width将图像大小调整到图像框控件中,仅用于显示目的 如果使用savepicture()保存图像,则保存的图像与加载的图像相同 Private Sub CommandButtonImage_Click() With Application.FileDialog(msoFileDialogFilePicker) .AllowMu
LoadPicture
加载一个已调整大小的图像。使用以下代码,我加载图像并调整其大小,但我现在了解到,Me.Image1.Width
将图像大小调整到图像框
控件中,仅用于显示目的
如果使用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
已解决。 根据建议,我使用了(以下内容适用于v7.0.2-4)
- 将应用程序目录添加到系统路径
- 为VBScript、VisualBasic和WSH安装ImageMagickObject OLE控件
以下代码打开一个对话框窗口以选择图像,调用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.您是否试图通过将图像加载到命令按钮来调整图像的大小??为什么?不,不,命令按钮打开一个对话框窗口(浏览文件),用户在其中选择图像。然后图像显示在
Me.Image1.Picture
image框中。LoadPicture具有可选的参数x,y,用于请求的高度/宽度。这对您有什么作用?LoadPicture
的xy
参数与设置图像的宽度或高度有关。我正在寻找一种方法来调整图像大小,然后将其保存(调整大小)到文件中。我只能考虑将图片导入形状,调整形状大小,将形状转换为剪贴板或对象数据,然后保存它。看起来太复杂了——您可以使用控制台脚本来处理图像,而不是使用imagemagick之类的东西。也许你会觉得很酷!很高兴看到你完成了。当我拒绝做我的通用cmd/console输出黑客时,你的回答可能对我也有帮助。