wdVBA保存图片到本地API

Private Type GUID
    Data1 As Long
    Data2 As Integer
    Data3 As Integer
    Data4(0 To 7) As Byte
End Type
Private Type GdiplusStartupInput
    GdiplusVersion As Long
    DebugEventCallback As Long
    SuppressBackgroundThread As Long
    SuppresexternalCodecs As Long
End Type
Private Type EncoderParameter
    GUID As GUID
    NumberOfValues As Long
    type As Long
    Value As Long
End Type
Private Type EncoderParameters
    Count As Long
    Parameter As EncoderParameter
End Type
Private Declare Function GdiplusStartup Lib "GDIPlus" (token As Long, inputbuf As GdiplusStartupInput, ByVal outputbuf As Long) As Long
Private Declare Function GdiplusShutdown Lib "GDIPlus" (ByVal token As Long) As Long
Private Declare Function GdipCreateBitmapFromHBITMAP Lib "GDIPlus" (ByVal hbm As Long, ByVal hpal As Long, Bitmap As Long) As Long
Private Declare Function GdipDisposeImage Lib "GDIPlus" (ByVal Image As Long) As Long
Private Declare Function GdipSaveImageToFile Lib "GDIPlus" (ByVal Image As Long, ByVal FileName As Long, clsidEncoder As GUID, encoderParams As Any) As Long

Private Declare Function CLSIDFromString Lib "ole32" (ByVal str As Long, id As GUID) As Long
Private Declare Function IsClipboardFormatAvailable Lib "user32" (ByVal wFormat As Integer) As Long
Private Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Integer) As Long
Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function CloseClipboard Lib "user32" () As Long
Const CF_BITMAP = 2
Public Sub SavePictures()
    Call ConvertShapeToInline
    Call SavePictureByApi
End Sub

Private Sub SavePictureByApi()
    Dim tSI As GdiplusStartupInput
    Dim lRes As Long
    Dim lGDIP As Long
    Dim lBitmap As Long
    Dim hBitmap As Long
    Dim FileName As String

    Dim inSh As InlineShape, N As Long
    N = 0

    ‘Documents.Open ("C:\Brildo\Test.docx")
    ReDim PicName(1 To 1) As String
    For Each inSh In ActiveDocument.InlineShapes
        ‘如果是shape,此处改为activedocument.Shapes,当然inSh的声明也要改

        N = N + 1
        ReDim Preserve PicName(1 To N)
        PicName(N) = FirstName & Format(N, "0000") & ".jpg"

        Debug.Print N

        FileName = ActiveDocument.Path & "\" & PicName(N)

        If Dir(FileName) <> "" Then Kill FileName

        inSh.Range.CopyAsPicture
        ‘如果为shape,CopyAsPicture方法无效,可能因为shape本身就是pic,
        ‘所以对于shape直接select,再copy,即以图片形式装入了粘贴板,
        ‘后续操作相同。
        OpenClipboard 0&
        hBitmap = GetClipboardData(CF_BITMAP)
        CloseClipboard
        tSI.GdiplusVersion = 1
        lRes = GdiplusStartup(lGDIP, tSI, 0)
        If lRes = 0 Then
            lRes = GdipCreateBitmapFromHBITMAP(hBitmap, 0, lBitmap)
            If lRes = 0 Then
                Dim tJpgEncoder As GUID
                Dim tParams As EncoderParameters
                CLSIDFromString StrPtr("{557CF401-1A04-11D3-9A73-0000F81EF32E}"), tJpgEncoder
                tParams.Count = 1
                With tParams.Parameter
                    CLSIDFromString StrPtr("{1D5BE4B5-FA4A-452D-9CDD-5DB35105E7EB}"), .GUID
                    .NumberOfValues = 1
                    .type = 4
                    .Value = VarPtr(100)
                End With
                lRes = GdipSaveImageToFile(lBitmap, StrPtr(FileName), tJpgEncoder, tParams)
                GdipDisposeImage lBitmap
            End If
            GdiplusShutdown lGDIP
        End If
    Next inSh
End Sub
Private Sub ConvertShapeToInline()
    Dim shp As Shape
    Dim N As Long
    If ActiveDocument.Shapes.Count = 0 Then Exit Sub
    On Error Resume Next    ‘防止一些转化失败
    For Each shp In ActiveDocument.Shapes
        Debug.Print "正在转换"; N
        N = N + 1
        shp.ConvertToInlineShape
    Next shp
    On Error GoTo 0
End Sub

  

时间: 2024-10-20 01:59:36

wdVBA保存图片到本地API的相关文章

JS/HTML 保存图片到本地:HTML &lt;a&gt; download 属性

JS如何保存图片到本地呢?自己百度一下吧! 这里想要说的是,可以利用 HTML 的 <a> 标签 来是实现保存图片到本地的功能,参考代码如下: <a href="http://wx.qlogo.cn/mmopen/ajNVdqHZLLDR2d0sYTtWb0ev4IRnQlM3z2NrD9kicibwMJYXWnwZIjxVo8uAeqdM7QB2WqjLWYBx1OSrOp8zpLbI5Y2VIibOKo2eclJVJcqd8k/0" download="

Android保存图片到本地相册

好久没有写东西了.备份下知识吧.免得忘记了 . 首先贴一段代码 --  这个是先生成一个本地的路径,将图片保存到这个文件中,然后扫描下sd卡.让系统相册重新加载下 .缺点就是只能保存到DCIM的文 件夹下边,暂时不知道怎么获取系统相机的路径,网上找了下说了好几个方法.其中有一条就是去读取本地的图片,然后根据一定的规则识别出本地相册的路径 保存下,不过觉得性能不是很好.谁有更好的方法可以提供下. private class DownloadTask extends AsyncTask<String

TCP练习1:服务器端读取图片并发送给客户端,客户端保存图片到本地

import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.InetAddress; import java.

Android学习笔记进阶18之画图并保存图片到本地

1.首先创建一个Bitmap图片,并指定大小: 2.在该图片上创建一个新的画布Canvas,然后在画布上绘制,并保存即可: 3.需要保存的目录File,注意如果写的目录如"/sdcard/song/"如果不存在的话,要先创建(file.mkdirs).. 4.需要添加权限:<uses-permission Android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> Canvas是一个画布,你可以建

Android学习笔记进阶18 之画图并保存图片到本地

1.首先创建一个Bitmap图片,并指定大小: 2.在该图片上创建一个新的画布Canvas,然后在画布上绘制,并保存即可: 3.需要保存的目录File,注意如果写的目录如"/sdcard/song/"如果不存在的话,要先创建(file.mkdirs).. 4.需要添加权限:<uses-permission Android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> Canvas是一个画布,你可以建

用archive保存图片到本地

源代码:http://url.cn/OaPZa2 今天用到了将archive图片保存到本地. 保存图片是不能用NSUserDefault来保存的,NSUserDefault只能保存基础的类型,并不能保存对象. 效果图: 代码: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. //初始化背景图 imageView=[[UIImageView alloc]ini

android保存图片到本地并可以在相册中显示出来

app应用是越来越人性化:界面优美,服务多样化,操作还非常方便.比如我们在用app的时候,发现上面有比较的图片想保存到手机,只要点一点app上提供的保存按钮就可以了.那这个图片保存到本地怎么实现的呢? 保存图片很简单,方法如下: /** 首先默认个文件保存路径 */ private static final String SAVE_PIC_PATH=Environment.getExternalStorageState().equalsIgnoreCase(Environment.MEDIA_M

python pyqtgraph 保存图片到本地

pyqtgraph官方给的示例居然会报错2333 官方文档传送门:#####pyqtgraph export pyqtgraph支持在可视化窗口中右键保存(Exporting from the GUI)试了一下只能保存为svg格式, 保存为png会闪退不知道是我这里的原因还是这里有bug,我希望直接生成图片(Exporting from the API) 先查看本地site-packages里面有test文件,里面有生成svg的版本画出来的图是svg格式只能放在浏览器看不能改后缀名 而我希望生成

【转】Flash AS3 保存图片到本地

核心提示:如果你想保存从视频,图表或表格中获取的图片数据到本地,可以使用BitmapData类. 原文地址: http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&productId=2&postId=8406 如果你想保存从视频,图表或表格中获取的图片数据到本地,可以使用BitmapData类. 摘要: 使用BitmapData类来创建一个包含了从组件中获取的图片数据的对象,使用mx.graphi