Excel Vba. Save resized image to file

前端 未结 1 1540
时光说笑
时光说笑 2020-12-20 05:25

I\'m trying to save to file a resized image loaded with LoadPicture. With the following code I load the image and resize it but I now understoo

相关标签:
1条回答
  • 2020-12-20 06:07

    SOLVED.

    As suggested, I used ImageMagick (the following applies to v7.0.2-4).

    1. Download the dynamic version ('Win32 dynamic at 16 bits-per-pixel component' or Win64)
    2. When installing select:
      • Add application directory to your system path
      • Install ImageMagickObject OLE control for VBScript, VisualBasic and WSH


    The following code opens a dialog window to select the image, calls ImageMagickObject OLE, resizes the image and saves it to a new file:

    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
    

    Other ImageMagick resize options.

    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题