⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gdimage.inc

📁 Powerbasic 对GDI 的操作 很漂亮的代码!
💻 INC
📖 第 1 页 / 共 5 页
字号:
'+--------------------------------------------------------------------------+
'|                                                                          |
'|                               GDImage.dll                                |
'|             Graphic control compatible GDI, GDIPLUS, OpenGL              |
'|                                                                          |
'|                              Version 4.00                                |
'+--------------------------------------------------------------------------+
'|                                                                          |
'|                         Author Patrice TERRIER                           |
'|                                                                          |
'|                         copyright(c) 2005-2007                           |
'|                                                                          |
'|                Patrice Terrier http://www.zapsolution.com                |
'|                                                                          |
'+--------------------------------------------------------------------------+
'|                  Project started on : 10-16-2005 (MM-DD-YYYY)            |
'|                        Last revised : 09-30-2007 (MM-DD-YYYY)            |
'+--------------------------------------------------------------------------+
'
'****************************************************************************
' CONSTANTS
'
  $GDIPLUSIMG        = ".DIB.EMF.GIF.JPG.JPEG.PNG.TIF.TIFF.WMF."
  $GDIPLUSEXT        = $GDIPLUSIMG + "BMP.ICO."
'
  $zLim              = "|"
  $Anti              = "\"
  $Dot               = "."
  $GDImageClassName  = "ZIMAGECTRL"  ' Class name for GDImage standard control.
  $GLImageClassName  = "ZOPENGLCTRL" ' Class name for OpenGL control.

' Internal GDImage structure being used to store details about each sprite object.
  %METADATA_SIZE   = 2048 '//See it in GDImage.inc
  TYPE ZOBJECT
      hWnd        AS LONG
      objType     AS LONG
      metacount   AS LONG
      metadata    AS STRING * %METADATA_SIZE
      'metastring  AS STRING * %METADATA_SIZE
      useFont     AS ASCIIZ * 128
      useSize     AS LONG
      fontFam     AS LONG
      curFont     AS LONG
      strFormat   AS LONG
      useARGB     AS LONG
      use3D       AS LONG
      x1          AS LONG ' x top coordinate
      y1          AS LONG ' y top coordinate
      x2          AS LONG ' window width
      y2          AS LONG ' window height
      visible     AS LONG
      order       AS LONG
      locked      AS BYTE
  
      ID          AS LONG
      Style       AS LONG
      Bitmap      AS LONG
      Region      AS LONG
      objLabel    AS STRING * 64
      xCapture    AS WORD
      yCapture    AS WORD
      opacity     AS BYTE ' PNG variable opacity
      scale       AS SINGLE '//2.10
      clone       AS LONG   '//2.10
      xP          AS WORD   '//2.11
      yP          AS WORD   '//2.11
      angle       AS WORD   '//2.11
      quality     AS BYTE   '//2.11
      flipmode    AS BYTE   '//3.00
      userotate   AS BYTE   '//3.00
      selected    AS BYTE   '//3.02
      hidden      AS BYTE   '//3.56
      reserved    AS STRING * 27' 28 ' 26
  END TYPE ' 2368 bytes
'
'****************************************************************************
' Version 1.00
' --------------------
' Load the GDImage.dll
' --------------------
' Must be done in the WinMain section BEFORE USING any of the GDImage function.
' Parameter: None
  DECLARE FUNCTION RegisterGDImageClass LIB "GDIMAGE.DLL" ALIAS "RegisterGDImageClass" () AS LONG
' Return:
' 0 = means failure, any other value means registered.
'****************************************************************************
'
'****************************************************************************
' Version 1.00
' Default function to create a GDImage control
' (Alias zCreateImageCtrl)
  DECLARE FUNCTION ZI_CreateWindow LIB "GDIMAGE.DLL" ALIAS "ZI_CreateWindow" ( _
  BYVAL hParent AS LONG, _  ' The Window/Dialog container
  BYVAL x AS LONG, _        ' The control top left corner horizontal location
  BYVAL y AS LONG, _        ' The control top left corner vertical location
  BYVAL xW AS LONG, _       ' The control width
  BYVAL yH AS LONG, _       ' The control height
  BYVAL ControlID AS LONG _ ' The control unique IDentifier
  ) AS LONG
' Return:
' The handle of the newly created control
'
' --------------------------------------
' Alternate methode using CreateWindowEx
' --------------------------------------
' Style&   = %WS_CHILD OR %WS_VISIBLE OR %WS_BORDER
' StyleEx& = 0
' CALL CreateWindowEx(StyleEx&, _
'                    "ZIMAGECTRL", _                 ' window class name
'                    "e:\pictures\image.png<fit>", _ ' Optional FullPathName to picture
'                     Style&, _                      ' window style
'                     10, _                          ' initial x position
'                     10, _                          ' initial y position
'                     150, _                         ' Calculate Window Width
'                     150, _                         ' Calculate Window Height
'                     hMain, _                       ' parent window handle
'                     %ID_THUMBCTRL, _               ' ControlID
'                     GetModuleHandle(""), _         ' program instance handle
'                     BYVAL 0)                       ' creation parameters
'
' ---------------------------------------
' Alternate methode using DDT CONTROL ADD
' ---------------------------------------
'  CONTROL ADD "ZIMAGECTRL", _
'              hDlg, _
'              %IDC_CUSTOMCONTROL, _
'              "e:\picture.jpg", _
'              10, 10, 640, 480, _
'              %WS_CHILD OR %WS_VISIBLE OR %WS_HSCROLL OR %WS_VSCROLL, _
'              %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR
'
'****************************************************************************
'
'****************************************************************************
' Version 1.00
' Display the common file selector dialog using thumbnail preview for the supported graphic format.
' (Alias zImageLoadDialog)
  DECLARE FUNCTION ZI_LoadDialog LIB "GDIMAGE.DLL" ALIAS "ZI_LoadDialog" ( _
  BYVAL hParent AS LONG _              ' The parent window handle.
  ) AS STRING
' Return:
' The FullPathName of the selected picture
'****************************************************************************
'
'****************************************************************************
' Version 1.00
' Display the common save to file dialog providing a valid hGDImageCtrl handle
' (Alias zImageSaveDialog)
  DECLARE FUNCTION ZI_SaveDialog LIB "GDIMAGE.DLL" ALIAS "ZI_SaveDialog" ( _
  BYVAL hParent AS LONG, _             ' The parent window handle.
  BYVAL hGDImageCtrl AS LONG _         ' The GDImage control handle.
  ) AS LONG
' Return:
' Successfull ErrCode& = 0
' Error       ErrCode
'****************************************************************************
'
'****************************************************************************
' Version 1.00
' Save the content of a GDImage control to any of the supported graphic format
' Must be a supported graphic format, see $GDIPLUSEXT.
  DECLARE FUNCTION ZI_SaveToFile LIB "GDIMAGE.DLL" ALIAS "ZI_SaveToFile" ( _
  zFullPathName AS ASCIIZ, _           ' Full path name of the graphic file to save.
  BYVAL hGDImageCtrl AS LONG, _        ' The GDimage control handle.
  OPTIONAL BYVAL JpegQuality AS LONG _ ' Optional JPEG encoding quality 1-100:
  ) AS LONG                            ' Default 0 = QalityMax = 100
' Return:
' Successfull ErrCode& = 0
' Error       ErrCode
'****************************************************************************
'
'****************************************************************************
' Version 1.00
' Set the image file to use with the control.
' Must be a supported graphic format, see $GDIPLUSEXT.
' (Alias zSetImageFromFile)
  DECLARE SUB ZI_SetFromFile LIB "GDIMAGE.DLL" ALIAS "ZI_SetFromFile" ( _
  BYVAL hGDImageCtrl AS LONG, _  ' The GDimage control handle.
  zFullPathName AS ASCIIZ _      ' Full path name to the graphic file to display
  )
' This function is the same than using :
' CALL SendMessage (hCtrl, %WM_SETTEXT, 0, STRPTR(FullPathName$))
'****************************************************************************
'
'****************************************************************************
' Version 1.00
' Set property of a GDImage control
' (Alias zGetProperty)
  DECLARE FUNCTION ZI_GetProperty LIB "GDIMAGE.DLL" ALIAS "ZI_GetProperty" ( _
  BYVAL hGDImageCtrl AS LONG, _ ' The GDimage control handle.
  BYVAL nProperty AS LONG _     ' A %ZI_ predefined constant (see the list below)
  ) AS LONG
' Return:
' The matching property value
'
' Get property from a GDImage control
' (Alias zSetProperty)
  DECLARE SUB ZI_SetProperty LIB "GDIMAGE.DLL" ALIAS "ZI_SetProperty" ( _
  BYVAL hGDImageCtrl AS LONG, _ ' The control handle.
  BYVAL nProperty AS LONG, _    ' A %ZI_ predefined constant (see the list below)
  BYVAL Parameter AS LONG _     ' A parameter matching the type of property to set.
  )
'
' See below the list of GDImage properties:
' Note: Constants prefixed with %ZI_ are for IMAGE control
  %ZI_DC             = 1  ' Internal DC
  %ZI_Bitmap         = 2  ' Memory Bitmap
  %ZI_Horizontal     = 3  ' Horizontal scrolling position
  %ZI_Vertical       = 4  ' Vertical scrolling position
  %ZI_GradientTop    = 5  ' Top gradiant color backgroud
  %ZI_GradientBottom = 6  ' Bottom gradiant color backgroud

  %ZI_FitToWindow    = 7  ' Resize the image to fit the view port
                          ' And use any of this constant as Parameter
                           %ZI_QualityDefault = -1
                           %ZI_QualityGood    = 1  ' Best performance
                           %ZI_QualityHigh    = 2  ' Best rendering quality
' DO NOT use or alter these properties!
  %ZI_PaintDC        = 8  ' Internal DC
  %ZI_PaintBitmap    = 9  ' Memory Bitmap
  %ZI_Reserved       = 10 ' Animated frame parameters : LOWRD = FrameWidth, HIWRD = FrameCount

  %ZI_ZoomWindow     = 11 ' Version 1.41
  %ZI_ZoomFactor     = 12 ' Version 1.41
  %ZI_Orientation    = 13 ' Version 1.41

  %ZI_FlagByte       = 14 ' Version 2.00 4 bytes reserved for flag
      %TOOL_CROP     = 1          ' Stored in the first byte
      %TOOL_CUTTER   = 2          ' Stored in the first byte
      %TOOL_PENCIL   = 4          ' Stored in the first byte
      %TOOL_FLOOD    = 8          ' Stored in the first byte
      %TOOL_AIRBRUSH = 16         ' Stored in the first byte
      %TOOL_PIPE     = 32         ' Stored in the first byte
      %TOOL_MOUSE    = 64         ' Stored in the first byte
      %TOOL_UNKNOWN  = 128        ' Stored in the first byte
  
  %Extend_cbWndExtra = %ZI_FlagByte ' %ZI_Orientation ' %ZI_Reserved

  %ZI_GDIPLUSHANDLE  = 1  ' Load GDIPLUS Image handle

  %ZD_MAPCOLORFROM   = &h807F80   ' Maping color for 32-bit alphablending
  %ZI_MAPCOLORFROM   = &hFF807F80 ' Maping color for 32-bit alphablending
  %ZI_MAPCOLORTO     = &hFF808080 ' Maping color for 32-bit alphablending
  %ZI_MAPCOLORNULL   = &h00807F80 ' Maping color for 32-bit alphablending
  %ZI_MAPTRANSCOLOR  = &h807F80   ' Transparent maped color for 32-bit alphablending
'
'****************************************************************************
'
'****************************************************************************
' Version 1.00
' Paint the background of a GDImage control
' see property %ZI_GradientTop
' and property %ZI_GradientBottom

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -