close

Trust Me!! Trust You!!


  • Blog
  • Local Log
  • Tag Cloud
  • Key Log
  • Guestbook
  • RSS Feed
  • Write a Post
  • Admin

혹시 블로그 스킨이 깨져 보이시나요? 최신버전의 Internet Explorer(Windows용), Opera, Firefox를 사용해보세요.

[VB] Creating thumbnails using GDI+

웹 프로그래밍
2012/05/07 11:09
 

[VB] Creating thumbnails using GDI+ (AKA How to resize an image with GDI+)


The CreateThumbnail function resizes a picture object returning the resized image in a new object. The new size can be smaller or greater than the original image size.


' ----==== GDI+ Declarations ====----

Private Type GdiplusStartupInput
   GdiplusVersion As Long
   DebugEventCallback As Long
   SuppressBackgroundThread As Long
   SuppressExternalCodecs As Long
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 GdipGetImageThumbnail Lib "GDIPlus" ( _
   ByVal Image As Long, _
   ByVal thumbWidth As Long, _
   ByVal thumbHeight As Long, _
   thumbImage As Long, _
   ByVal callback As Long, _
   ByVal callbackData As Long) As Long
  
Private Declare Function GdipDisposeImage Lib "GDIPlus" ( _
   ByVal Image As Long) As Long

Private Declare Function GdipCreateHBITMAPFromBitmap Lib "GDIPlus" ( _
   ByVal Bitmap As Long, _
   hbmReturn As Long, _
   ByVal background As Long) As Long

' ----==== OLE API Declarations ====----

Private Type PICTDESC
   cbSizeOfStruct As Long
   picType As Long
   hgdiObj As Long
   hPalOrXYExt As Long
End Type

Private Type IID
   Data1 As Long
   Data2 As Integer
   Data3 As Integer
   Data4(0 To 7)  As Byte
End Type

Private Declare Sub OleCreatePictureIndirect Lib "oleaut32.dll" ( _
   lpPictDesc As PICTDESC, _
   riid As IID, _
   ByVal fOwn As Boolean, _
   lplpvObj As Object)

'----------------------------------------------------------
' Procedure : CreateThumbnail
' Purpose   : Creates a thumbnail of a picture
'----------------------------------------------------------
'
Function CreateThumbnail( _
   ByVal Image As StdPicture, _
   ByVal Width As Long, _
   ByVal Height As Long) As StdPicture
Dim tSI As GdiplusStartupInput
Dim lGDIP As Long
Dim lRes As Long
Dim lBitmap As Long

   ' Initialize GDI+
   tSI.GdiplusVersion = 1
   lRes = GdiplusStartup(lGDIP, tSI)
  
   If lRes = 0 Then
  
      ' Create a GDI+ Bitmap from the image handle
      lRes = GdipCreateBitmapFromHBITMAP(Image.Handle, 0, lBitmap)
  
      If lRes = 0 Then
     
         Dim lThumb As Long
         Dim hBitmap As Long
        
         ' Create the thumbnail
         lRes = GdipGetImageThumbnail(lBitmap, Width, Height, _
                                      lThumb, 0, 0)
     
         If lRes = 0 Then
           
            ' Create a GDI bitmap from the thumbnail
            lRes = GdipCreateHBITMAPFromBitmap(lThumb, hBitmap, 0)
     
            ' Create the StdPicture object
            Set CreatheThumbnail = HandleToPicture(hBitmap, _
                                      vbPicTypeBitmap)
        
            ' Dispose the thumbnail image
            GdipDisposeImage lThumb
        
         End If
        
         ' Dispose the image
         GdipDisposeImage lBitmap
     
      End If
     
      ' Shutdown GDI+
      GdiplusShutdown lGDIP
     
   End If
  
   If lRes Then Err.Raise 5, , "Cannot load file"
  
End Function

'----------------------------------------------------------
' Procedure : HandleToPicture
' Purpose   : Creates a StdPicture object to wrap a GDI
'             image handle
'----------------------------------------------------------
'
Public Function HandleToPicture( _
   ByVal hGDIHandle As Long, _
   ByVal ObjectType As PictureTypeConstants, _
   Optional ByVal hpal As Long = 0) As StdPicture
Dim tPictDesc As PICTDESC
Dim IID_IPicture As IID
Dim oPicture As IPicture
   
   ' Initialize the PICTDESC structure
   With tPictDesc
      .cbSizeOfStruct = Len(tPictDesc)
      .picType = ObjectType
      .hgdiObj = hGDIHandle
      .hPalOrXYExt = hpal
   End With
   
   ' Initialize the IPicture interface ID
   With IID_IPicture
      .Data1 = &H7BF80981
      .Data2 = &HBF32
      .Data3 = &H101A
      .Data4(0) = &H8B
      .Data4(1) = &HBB
      .Data4(3) = &HAA
      .Data4(5) = &H30
      .Data4(6) = &HC
      .Data4(7) = &HAB
   End With
   
   ' Create the object
   OleCreatePictureIndirect tPictDesc, IID_IPicture, _
                            True, oPicture
   
   ' Return the picture object
   Set HandleToPicture = oPicture
       
End Function

 

 

출처 : http://www.mvps.org/emorcillo/en/code/vb6/thumbnail.shtml

이올린에 북마크하기
No received trackback. / No comment.

Trackback Address :: http://viper150.cafe24.com/trackback/179

You can also say.

Prev 1 ... 121 122 123 124 125 126 127 128 129 ... 298 Next
블로그 이미지
이것저것 불펌금지도 퍼다가 담습니다. 외부에 비공개된 페이지 입니다. By. 어른왕자

카테고리

  • 전체 (298)
    • 사는 이야기 (115)
    • 웹 프로그래밍 (102)
    • App 프로그래밍 (22)
    • IT 뉴스&기타 (22)
    • 박한별 (4)
    • 역사&기타지식 (9)

태그목록

  • hwpCtrl
  • hiddenmenu
  • java api
  • 붕당
  • vga성능
  • api 한글화
  • 속담
  • 코막
  • 사드
  • 변화구
  • 자바스크립트 마우스 막기
  • 오지호
  • 경찰
  • ROOT
  • java.util.List
  • 광고제거
  • 조선
  • 의사결정
  • 아이폰6
  • 빌리조엘
  • 대결
  • 자본
  • kbs
  • 크론탭
  • 육이오
  • 드라마
  • web.xml
  • 운동
  • substring
  • spring

최근에 올라온 글

  • 보험사의 조정신청 대응방법.
  • 어느 천재의 앞선 시선.
  • [병맛더빙] 누구게..... (1)
  • 韓경제 `회색 코뿔소` 상황...
  • SVN Connector 설치 URL.
  • 군대를 가지 않는 서울대생.
  • “운은 하늘의 귀여움 받는...
  • 목장에서 알바하다가 캐스...
  • [펌]믿고 거르는 관상.
  • 하루에 1세트씩 하면 좋다...

최근에 달린 댓글

  • <p align="center"><a href="h... 라임애드 02/14
  • <div style="OVERFLOW: hidden... 고사니 02/12
  • <p align="center"><a href="h... 라임정보 02/07
  • <p><img src="https://i.imgur... 브레드 01/22
  • <p><img src="https://i.imgur... 브레드 01/22

최근에 받은 트랙백

  • công ty may đồng phục. công ty may đồng phục 01/08
  • Israelnightclub`s recent blo... Israelnightclub`s recent blo.. 01/06
  • Suggested Browsing. Suggested Browsing 01/06
  • similar site. similar site 01/06
  • לאתר הבית שלנו. לאתר הבית שלנו 01/06

글 보관함

  • 2019/03 (1)
  • 2018/12 (1)
  • 2018/09 (1)
  • 2018/08 (1)
  • 2018/02 (1)

달력

«   2021/02   »
일 월 화 수 목 금 토
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28            

링크

  • Total : 263351
  • Today : 11
  • Yesterday : 29
Tattertools
Eolin
rss

어른왕자's blog is powered byTattertools1.1.2.2 : Animato