It is currently Fri Jul 03, 2020 8:35 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: LoadImageEx
PostPosted: Fri Nov 29, 2019 12:42 am 
Offline
Addict
Addict

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1907
Load BMP, GIF, JPG, PNG (and more) images without the PureBasic image plugins (UseGIFImageDecoder, etc).

Not my code, but no topic exists for it, so I made one. :)

Code:
Procedure LoadImageEx(imgnum,file$,depth=24)
  Interface nIDXSurfaceFactory
    QueryInterface(a,b) : AddRef() : Release() : CreateSurface(a,b,c,d,e,f,g,h) : CreateFromDDSurface(a,b,c,d,e,f) : LoadImage(a.p-bstr,b,c,d,e,f)
    LoadImageFromStream(a,b,c,d,e,f) : CopySurfaceToNewFormat(a,b,c,d,e) : CreateD3DRMTexture(a,b,c,d,e) : BitBlt(a,b,c,d,e)
  EndInterface
  result=CoInitialize_(0)
  If result=#S_FALSE Or result=#S_OK
    #DXLOCKF_READ=0 : #CLSCTX_INPROC_SERVER=1
    CoCreateInstance_(?CLSID_DXTransformFactory,0,#CLSCTX_INPROC_SERVER,?IID_IDXTransformFactory,@dxtf.IDXTransformFactory)
    If dxtf
      dxtf\QueryService(?IID_IDXSurfaceFactory,?IID_IDXSurfaceFactory,@dxsf.nIDXSurfaceFactory)
      If dxsf
        dxsf\LoadImage(file$,0,0,0,?IID_IDXSurface,@surf.IDXSurface)
        If surf
          surf\LockSurfaceDC(0,#INFINITE,#DXLOCKF_READ,@lock.IDXDCLock)
          If lock
            DC=lock\GetDC()
            If DC
              GetClipBox_(DC,re.rect)
              If imgnum=#PB_Any
                result=CreateImage(#PB_Any,re\right,re\bottom,depth) : imgnum=result
              Else
                result=CreateImage(imgnum,re\right,re\bottom,depth)
              EndIf
              If result
                DestDC=StartDrawing(ImageOutput(imgnum))
                If DestDC : ok=BitBlt_(DestDC,0,0,re\right,re\bottom,DC,0,0,#SRCCOPY) : StopDrawing() : EndIf
                If ok=#False : FreeImage(imgnum) : Else : ok=result : EndIf
              EndIf
            EndIf
            Lock\Release()
          EndIf
          surf\Release()
        EndIf
        dxsf\Release()
      EndIf
      dxtf\Release()
    EndIf
  EndIf
  CoUninitialize_()
  ProcedureReturn ok
  DataSection
  CLSID_DXTransformFactory:
    Data.l $D1FE6762
    Data.w $FC48,$11D0
    Data.b $88,$3A,$3C,$8B,$00,$C1,$00,$00
  IID_IDXTransformFactory:
    Data.l $6A950B2B
    Data.w $A971,$11D1
    Data.b $81,$C8,$00,$00,$F8,$75,$57,$DB
  IID_IDXSurfaceFactory:
    Data.l $144946F5
    Data.w $C4D4,$11D1
    Data.b $81,$D1,$00,$00,$F8,$75,$57,$DB
  IID_IDXSurface:
    Data.l $B39FD73F
    Data.w $E139,$11D1
    Data.b $90,$65,$00,$C0,$4F,$D9,$18,$9D
  EndDataSection
EndProcedure


Top
 Profile  
Reply with quote  
 Post subject: Re: LoadImageEx
PostPosted: Fri Nov 29, 2019 8:01 am 
Offline
Addict
Addict
User avatar

Joined: Tue Oct 09, 2007 2:15 am
Posts: 1126
Original at german forum from stefan : https://www.purebasic.fr/german/viewtopic.php?t=12155

Also with :
LoadSpriteEx()
CatchSpriteEx()
and CatchImageEx()

_________________
PureBasic 5.72 LTS (Windows x86/x64) | Windows10 Pro x64 | Z370 Extreme4 | i7 8770k | 32GB RAM | iChill GeForce RTX 2080 Super | HAF XF Evo​​
English is not my native language... (I often use DeepL to translate my texts.)


Top
 Profile  
Reply with quote  
 Post subject: Re: LoadImageEx
PostPosted: Fri Nov 29, 2019 8:43 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3622
Location: Netherlands
I also created a module a few years ago to load and save images.
viewtopic.php?f=12&t=66497
But it works in a different way (it uses the normal PB commands).

_________________
macOS 10.15 Catalina, Windows 10


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 17 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye