Загрузка картинки с помощью GDI+

 

Самая противная тема - это GDI+. Структуры и функции объявлены кое-как, примеры на форумах - сплошной говнокод. Вот я и пытаюсь набрать готовые примеры.

;https://docs.microsoft.com/en-us/windows/win32/api/gdiplustypes/ne-gdiplustypes-status
;https://www.devhut.net/deleting-all-an-images-properties-using-the-gdi-api/
;https://www.manhunter.ru/assembler/923_vivod_izobrazheniya_na_assemblere_s_pomoschyu_gdi.html
Structure GdiplusStartupInput
  GdiplusVersion.l;           dd ?
  DebugEventCallback.l;       dd ?
  SuppressBackgroundThread.l; dd ?
  SuppressExternalCodecs.l  ;   dd ?
EndStructure
Import "gdiplus.lib"
  GdiplusStartup(token, *input.GdiplusStartupInput, output) 
  GdiplusShutdown(token)
  GdipCreateBitmapFromFile(filename.s, *bitmap)
  GdipGetImageWidth(*image, *width)
  GdipGetImageHeight(*image, *height)
  GdipCreateHBITMAPFromBitmap(*bitmap, *hbmReturn, *background)
  GdipDisposeImage(image)
  GdipDeleteGraphics(Graphics)
EndImport


gdiplusSInput.GdiplusStartupInput
; Инициализация GDI+
gdiplusSInput\GdiplusVersion=1
gdiplusSInput\DebugEventCallback=0
gdiplusSInput\SuppressBackgroundThread=0
gdiplusSInput\SuppressExternalCodecs=0
GdiplusStartup(@gdiplusToken,@gdiplusSInput,0)
If gdiplusToken
  If GdipCreateBitmapFromFile("picture.jpg", @image)=0
    GdipGetImageWidth(image,@iw)
    GdipGetImageHeight(image,@ih)
    If iw<>0 And ih<>0
      hBitmap=0
      SC=GdipCreateHBITMAPFromBitmap(image,@hBitmap,$00FFFFFF)
      If SC=0
        If OpenWindow(0, 0, 0, iw, ih, "ImageGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
          ImageGadget(1, 0, 0, iw, ih, hBitmap, #PB_Image_Border)
          Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
        EndIf
        
        rr=GdipDisposeImage(image)
        ;rr=GdipDeleteGraphics(hGraphics);ONLY after invoke GdipCreateFromHDC, ps.hdc, ADDR hGraphics
      Else
        Debug "error GdipCreateHBITMAPFromBitmap"
      EndIf
    Else
      Debug Str(iw)+"x"+Str(ih)
    EndIf
  Else
    Debug "error GdipCreateBitmapFromFile"
  EndIf
  GdiplusShutdown(token)
EndIf

Комментарии