VB中使用GDI+进行图像缩放的实例
生活随笔
收集整理的這篇文章主要介紹了
VB中使用GDI+进行图像缩放的实例
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
? ?VISUAL BASIC(VB)對圖形圖像的處理一直以來是弱項,并受到很多人的垢病。關于圖形圖像的放大縮小,一般使用PICTUREBOX的PAINTPICTURE方法來處理。但這個處理方法最大的問題就是圖像的失真。比方說圖像中原來有網格線的,處理以后網格線會丟失,處理效果不好。后來在網上找到幾個材料,是關于GDI+的用法的。試驗了一下,果然效果非凡。以下為程序處理的關鍵代碼:
Private Type GdiplusStartupInputGdiplusVersion As LongDebugEventCallback As LongSuppressBackgroundThread As Long SuppressExternalCodecs As Long End Type Private Enum GpStatus 'StatusOk = 0GenericError = 1InvalidParameter = 2OutOfMemory = 3ObjectBusy = 4InsufficientBuffer = 5NotImplemented = 6Win32Error = 7WrongState = 8Aborted = 9FileNotFound = 10ValueOverflow = 11AccessDenied = 12UnknownImageFormat = 13FontFamilyNotFound = 14FontStyleNotFound = 15NotTrueTypeFont = 16UnsupportedGdiplusVersion = 17GdiplusNotInitialized = 18PropertyNotFound = 19PropertyNotSupported = 20 End Enum Private Declare Function GdiplusStartup Lib "gdiplus" (token As Long, inputbuf As GdiplusStartupInput, Optional ByVal outputbuf As Long = 0) As GpStatus Private Declare Function GdiplusShutdown Lib "gdiplus" (ByVal token As Long) As GpStatus Private Declare Function GdipDrawImageRect Lib "gdiplus" (ByVal graphics As Long, ByVal Image As Long, ByVal X As Single, ByVal Y As Single, ByVal Width As Single, ByVal Height As Single) As GpStatus Private Declare Function GdipCreateFromHDC Lib "gdiplus" (ByVal hDC As Long, graphics As Long) As GpStatus Private Declare Function GdipDeleteGraphics Lib "gdiplus" (ByVal graphics As Long) As GpStatus Private Declare Function GdipLoadImageFromFile Lib "gdiplus" (ByVal filename As String, Image As Long) As GpStatus Private Declare Function GdipDisposeImage Lib "gdiplus" (ByVal Image As Long) As GpStatus Dim gdip_Token As Long Dim gdip_Image As Long Dim gdip_Graphics As Long '-------------------------------------- '-- 使用者請保留作者版權 '-- 作者:BEAR-BEN '-- QQ:453628001 '-------------------------------------- '-------------縮略圖函數----------- Public Sub ShowTNImg(PBox As Object, ImagePath As String, WidthMax As Long, HeightMax As Long)LoadGDIPIf GdipCreateFromHDC(PBox.hDC, gdip_Graphics) <> 0 ThenMsgBox "出現錯誤!", vbCritical, "錯誤"GdiplusShutdown gdip_TokenEndEnd If'載入圖片到內存中GdipLoadImageFromFile StrConv(ImagePath, vbUnicode), gdip_Image'使用GDI+直接從內存中縮略并繪圖,GDI+有很好的反鋸齒能力If GdipDrawImageRect(gdip_Graphics, gdip_Image, 0, 0, WidthMax, HeightMax) <> Ok Then Debug.Print "顯示失敗。。。"DisposeGDIP End Sub Public Sub LoadGDIP()Dim GpInput As GdiplusStartupInputGpInput.GdiplusVersion = 1If GdiplusStartup(gdip_Token, GpInput) <> 0 ThenMsgBox "加載GDI+失敗!", vbCritical, "加載錯誤"EndEnd If End Sub Public Sub DisposeGDIP()GdipDisposeImage gdip_ImageGdipDeleteGraphics gdip_GraphicsGdiplusShutdown gdip_Token End Sub轉載于:https://blog.51cto.com/vbcodeworkers/1356907
總結
以上是生活随笔為你收集整理的VB中使用GDI+进行图像缩放的实例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 小谈深度优先搜索
- 下一篇: 苹方字体 for linux,苹果苹方字