gpt4 book ai didi

Excel Vba。将调整大小的图像保存到文件

转载 作者:行者123 更新时间:2023-12-04 21:59:09 25 4
gpt4 key购买 nike

我正在尝试 将调整大小的图像保存到文件 满载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

最佳答案

解决了。
按照建议,我使用了 ImageMagick (以下适用于 v7.0.2-4)。

  • Download动态版本('Win32 dynamic at 16 bits-per-pixel component' 或 Win64)
  • 安装时选择:
  • 将应用程序目录添加到您的系统路径
  • 为 VBScript、VisualBasic 和 WSH 安装 ImageMagickObject OLE 控件


  • enter image description here

    以下代码打开一个对话框窗口以选择图像,调用 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 .

    关于Excel Vba。将调整大小的图像保存到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38351838/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com