Posted: Sun Aug 17, 2008 1:32 pm
@srod (or anyone)
Can we use this method (Gdi+) to read JPEG in PB too?
Can we use this method (Gdi+) to read JPEG in PB too?
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
#GDIPLUS_OK = 0
;-Structures.
Structure GdiplusStartupInput ;{
GdiPlusVersion.l
*DebugEventCallback.DebugEventProc
SuppressBackgroundThread.l
SuppressExternalCodecs.l
EndStructure
;-Imports.
Import "gdiplus.lib"
GdiplusStartup(token, *input.GdiplusStartupInput, output)
GdipCreateBitmapFromFile(filename.p-unicode, *bitmap)
GdipGetImageWidth(*image, *width)
GdipGetImageHeight(*image, *height)
GdipCreateFromHDC(hdc.l, *graphics)
GdipDrawImageRectI(*graphics, *image, x.l, y.l, width.l, height.l)
GdipDeleteGraphics(*graphics)
GdipDisposeImage(image)
GdiplusShutdown(token)
EndImport
;Returns zero if an error or the PB image#.
Procedure.l LoadJPG(filename$)
Protected result, width, height
Protected input.GdiplusStartupInput, token, image, imageID, hdc, graphics
;First initialise gdi+.
input\GdiPlusVersion = 1
GdiplusStartup(@token, @input, #Null)
;Was the initialisation successful?
If token
If GdipCreateBitmapFromFile(filename$, @image) = #GDIPLUS_OK
GdipGetImageWidth(image, @width)
GdipGetImageHeight(image, @height)
imageID = CreateImage(#PB_Any, Width, Height, 32)
If imageID
hdc = StartDrawing(ImageOutput(imageID))
If hdc
GdipCreateFromHDC(hdc, @graphics)
If graphics
GdipDrawImageRectI(graphics, image, 0, 0, width, height)
GdipDeleteGraphics(graphics)
result = imageID
EndIf
StopDrawing()
EndIf
EndIf
GdipDisposeImage(image)
EndIf
;Tidy up.
GdiplusShutdown(token)
EndIf
ProcedureReturn result
EndProcedure
;Test.
imageNum = LoadJPG("test.jpg")
Code: Select all
#GDIPLUS_OK = 0
#PixelFormat32bppARGB = 2498570
;-Structures.
Structure GdiplusStartupInput ;{
GdiPlusVersion.l
*DebugEventCallback.DebugEventProc
SuppressBackgroundThread.l
SuppressExternalCodecs.l
EndStructure
;-Imports.
Import "gdiplus.lib"
GdiplusStartup(token, *input.GdiplusStartupInput, output)
GdipCreateBitmapFromFile(filename.p-unicode, *bitmap)
GdipCreateHBITMAPFromBitmap(*bitmap, *image, background)
GdipDisposeImage(image)
GdiplusShutdown(token)
EndImport
;Returns zero if an error or the PB image#.
Procedure.l LoadJPG(filename$)
Protected result, width, height
Protected input.GdiplusStartupInput, token, image, imageID, hdc, graphics
;First initialise gdi+.
input\GdiPlusVersion = 1
GdiplusStartup(@token, @input, #Null)
;Was the initialisation successful?
If token
If GdipCreateBitmapFromFile(filename$, @image) = #GDIPLUS_OK
GdipCreateHBITMAPFromBitmap(image, @result, #PixelFormat32bppARGB)
GdipDisposeImage(image)
EndIf
;Tidy up.
GdiplusShutdown(token)
EndIf
ProcedureReturn result
EndProcedure
;Test.
imageID = LoadJPG("test.jpg")
Thanks for your info but i im newbie, so still waitingAs I say if I had the time I'd hack up some code for you.