設為首頁收藏本站Access中國

Office中國論壇/Access中國論壇

 找回密碼
 注冊

QQ登錄

只需一步,快速開始

123下一頁
返回列表 發(fā)新帖
查看: 6432|回復: 23
打印 上一主題 下一主題

[模塊/函數(shù)] 保存StdPicture到JPG圖片文件的函數(shù)

[復制鏈接]

點擊這里給我發(fā)消息

跳轉(zhuǎn)到指定樓層
1#
發(fā)表于 2008-1-5 16:40:21 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
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
        SuppressExternalCodecs   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, _
        Optional ByVal outputbuf As Long = 0) 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
   
  '   ----====   SaveJPG   ====----
   
  Public Sub SaveJPG( _
        ByVal pict As StdPicture, _
        ByVal FileName As String, _
        Optional ByVal quality As Byte = 80)
  Dim tSI     As GdiplusStartupInput
  Dim lRes     As Long
  Dim lGDIP     As Long
  Dim lBitmap     As Long
   
        '   Initialize   GDI+
        tSI.GdiPlusVersion = 1
        lRes = GdiplusStartup(lGDIP, tSI)
         
        If lRes = 0 Then
         
              '   Create   the   GDI+   bitmap
              '   from   the   image   handle
              lRes = GdipCreateBitmapFromHBITMAP(pict.Handle, 0, lBitmap)
         
              If lRes = 0 Then
                    Dim tJpgEncoder     As Guid
                    Dim TParams     As EncoderParameters
                     
                    '   Initialize   the   encoder   GUID
                    CLSIDFromString StrPtr("{557CF401-1A04-11D3-9A73-0000F81EF32E}"), _
                                                    tJpgEncoder
               
                    '   Initialize   the   encoder   parameters
                    TParams.Count = 1
                    With TParams.Parameter     '   Quality
                          '   Set   the   Quality   GUID
                          CLSIDFromString StrPtr("{1D5BE4B5-FA4A-452D-9CDD-5DB3505E7EB}"), .Guid
                          .NumberOfValues = 1
                          .type = 1
                          .Value = VarPtr(quality)
                    End With
                     
                    '   Save   the   image
                    lRes = GdipSaveImageToFile( _
                                      lBitmap, _
                                      StrPtr(FileName), _
                                      tJpgEncoder, _
                                      TParams)
                                                              
                    '   Destroy   the   bitmap
                    GdipDisposeImage lBitmap
                     
              End If
               
              '   Shutdown   GDI+
              GdiplusShutdown lGDIP
   
        End If
         
        If lRes Then
              Err.Raise 5, , "Cannot   save   the   image.   GDI+   Error:" & lRes
        End If
         
  End Sub
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享分享 分享淘帖 訂閱訂閱
2#
發(fā)表于 2008-1-5 17:09:16 | 只看該作者
不錯 , 收藏先
3#
發(fā)表于 2008-1-5 17:59:18 | 只看該作者
收藏
4#
發(fā)表于 2008-1-5 22:28:38 | 只看該作者
噢,cuxun兄ole automation這個不是自動引用的嗎
5#
發(fā)表于 2008-1-5 22:31:17 | 只看該作者
收藏了
6#
發(fā)表于 2008-1-5 22:36:37 | 只看該作者
用了不少API函數(shù),收藏~
7#
發(fā)表于 2008-1-5 22:52:24 | 只看該作者
對這個實在是不懂。。!

點擊這里給我發(fā)消息

8#
發(fā)表于 2008-1-5 23:40:03 | 只看該作者
收藏......
9#
發(fā)表于 2008-1-7 20:56:24 | 只看該作者
汗,這個,能弄個例子嗎
10#
發(fā)表于 2008-1-19 17:13:05 | 只看該作者
導出IMAGE控件圖片的需另加loadpicture
SaveJPG LoadPicture(Me.Image0.Picture), "C:\DD.bmp"
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則

QQ|站長郵箱|小黑屋|手機版|Office中國/Access中國 ( 粵ICP備10043721號-1 )  

GMT+8, 2024-10-23 06:24 , Processed in 0.210457 second(s), 33 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回復 返回頂部 返回列表