|
論壇說明 |
歡迎您來到『史萊姆論壇』 ^___^ 您目前正以訪客的身份瀏覽本論壇,訪客所擁有的權限將受到限制,您可以瀏覽本論壇大部份的版區與文章,但您將無法參與任何討論或是使用私人訊息與其他會員交流。若您希望擁有完整的使用權限,請註冊成為我們的一份子,註冊的程序十分簡單、快速,而且最重要的是--註冊是完全免費的! 請點擊這裡:『註冊成為我們的一份子!』 |
|
主題工具 | 顯示模式 |
2009-07-24, 03:56 PM | #1 |
註冊會員
|
疑問 - VB6.0另存圖檔的功能
各位先進們好,今天做了一個另存新檔的功能,但打開存好的圖檔卻無法顯示,程式碼如下: 語法:
Private Sub save_Click() CommonDialog2.Filter = "JPEG(*.jpg)|*.jpg" CommonDialog2.FilterIndex = 2 CommonDialog2.ShowSave If Not CommonDialog2.FileName = "" Then Dim fso, MyFile Set fso = CreateObject("Scripting.FileSystemObject") Set MyFile = fso.CreatePictureFile(CommonDialog2.FileName, True) MyFile.WriteLine (Picture1.Picture) MyFile.Close Set fso = Nothing Set MyFile = Nothing MsgBox "儲存成功" End If End Sub 但不知怎麼改才對,Run程式時出現錯誤訊息,謝謝。 PS:會出現執行階段錯誤'438'物件不支援此屬性或方法,指的就是我上面那行。 |
送花文章: 25,
|
2009-07-27, 01:25 PM | #4 (permalink) |
管理版主
|
那你可能要引入外掛DLL嘍~
(用過 PaintX.dll、GflAx.dll,其中 GflAx.dll功能比較強大,但掛上 DLL編譯成軟體移植時就必須帶著走 軟體需打包成安裝檔方式,也就大多了...) 個人以前也找過相關用API來實現 提供一個 ... 運行前請確認系統內(C:\WINDOWS\system32)是否有 GDIPLUS.DLL (這是一個微軟的程式庫,理論上大家都會有才對) 語法:
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 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 '初始化 GDI+ tSI.GdiplusVersion = 1 lRes = GdiplusStartup(lGDIP, tSI) If lRes = 0 Then '從句柄創建 GDI+ 圖像 lRes = GdipCreateBitmapFromHBITMAP(pict.handle, 0, lBitmap) If lRes = 0 Then Dim tJpgEncoder As GUID Dim tParams As EncoderParameters '初始化解碼器的GUID標識 CLSIDFromString StrPtr("{557CF401-1A04-11D3-9A73-0000F81EF32E}"), tJpgEncoder '設置解碼器參數 tParams.Count = 1 With tParams.Parameter ' Quality '得到Quality參數的GUID標識 CLSIDFromString StrPtr("{1D5BE4B5-FA4A-452D-9CDD-5DB35105E7EB}"), .GUID .NumberOfValues = 1 .type = 4 .Value = VarPtr(quality) End With '保存圖像 lRes = GdipSaveImageToFile( _ lBitmap, _ StrPtr(filename), _ tJpgEncoder, _ tParams) '銷毀GDI+圖像 GdipDisposeImage lBitmap End If '銷毀 GDI+ GdiplusShutdown lGDIP End If If lRes Then Err.Raise 5, , "不能保存這個圖像:" & lRes End Sub SaveJPG PictureBox1.Image, "c:\1.jpg", 100 '品質從1~100 此帖於 2009-08-02 10:22 AM 被 mini 編輯. |
送花文章: 2013,
|
向 mini 送花的會員:
|
chung1206 (2009-07-27)
感謝您發表一篇好文章 |
|
|
相似的主題 | ||||
主題 | 主題作者 | 討論區 | 回覆 | 最後發表 |
疑問 - XP: 檔案總管裡的圖檔預覽功能消失? | latenight | 一般電腦疑難討論區 | 7 | 2008-01-25 07:13 PM |
XP另存圖片都自動變成BMP @@? | kumo | 軟體應用問題討論區 | 4 | 2004-01-29 01:13 AM |
用 IE 存圖檔時的怪現象 | ltu6323 | 一般電腦疑難討論區 | 0 | 2003-08-05 06:01 PM |
請問如何將word檔的資料轉成圖檔ㄚ | 風色幻想 | 軟體應用問題討論區 | 2 | 2003-03-15 12:57 PM |