I have changed step by step until crash gone (by now but have to test more to be sure)
The only (for now that I discovered after crash gone) is according to code:
Code: Select all
Declare.i GetBlobImg(dbSession, guid.s)
Declare PrintImg(dbSession, guid$)
Declare.i imgm_InvertColors(iMg.i)
Declare.i GRAY(iMg.i) ; Ctrl+G
#imGad=10
;{ Problemmy
Procedure.i GetBlobImg(dbSession, guid.s)
Protected imgMemBlobSize, imgMemCMPsize
If DatabaseQuery(dbSession,"SELECT * FROM imgTbl WHERE LOWER(guid)='"+LCase(guid)+"' LIMIT 1")
Protected imgColIndex.l=DatabaseColumnIndex(dbSession,"img")
If imgColIndex>=0
NextDatabaseRow(dbSession)
imgMemBlobSize=DatabaseColumnSize(dbSession,imgColIndex)
If imgMemBlobSize
Protected *imgMem = AllocateMemory(imgMemBlobSize)
GetDatabaseBlob(dbSession,imgColIndex,*imgMem,imgMemBlobSize)
Protected iMg.i=CatchImage(#PB_Any,*imgMem)
FreeMemory(*imgMem)
EndIf
EndIf
FinishDatabaseQuery(dbSession)
EndIf
ProcedureReturn iMg
EndProcedure
Procedure PrintImg(dbSession, guid$)
Protected tmpImg.i, iMg.i=GetBlobImg(dbSession, guid$)
If IsImage(iMg) ; change path/filename to your own 32x32 pixel image
tmpImg = GRAY(iMg)
FreeImage(iMg)
iMg=imgm_InvertColors(tmpImg)
If IsImage(iMg)
SaveImage(iMg,Path.s);SetGadgetState(#imGad, ImageID(iMg)):SetActiveGadget(#imGad)
FreeImage(iMg)
EndIf
If IsImage(tmpImg)
FreeImage(tmpImg)
EndIf
EndIf
EndProcedure
;}
;{ Working
Structure myBITMAPINFO
bmiHeader.BITMAPINFOHEADER
bmiColors.RGBQUAD[1]
EndStructure
Procedure.i imgm_InvertColors(iMg.i)
;Invert the colors
Protected tmpImg.i=CopyImage(iMg, #PB_Any)
hBmp=ImageID(tmpImg)
If hBmp
imageWidth=ImageWidth(tmpImg)
imageHeight=ImageHeight(tmpImg)
mem=AllocateMemory(imageWidth*imageHeight*4)
bmi.myBITMAPINFO
bmi\bmiHeader\biSize = SizeOf(BITMAPINFOHEADER)
bmi\bmiHeader\biWidth = imageWidth
bmi\bmiHeader\biHeight = imageHeight
bmi\bmiHeader\biPlanes = 1
bmi\bmiHeader\biBitCount = 32
bmi\bmiHeader\biCompression = #BI_RGB
hdc = StartDrawing(ImageOutput(tmpImg))
Debug hdc
GetDIBits_(hdc,hBmp,0,imageHeight,mem,bmi,#DIB_RGB_COLORS)
*pixels.LONG = mem
For A = 1 To imageWidth*(imageHeight)
*pixels\l - *pixels\l - *pixels\l
*pixels + 4
Next A
SetDIBits_(hdc,hBmp,0,imageHeight,mem,bmi,#DIB_RGB_COLORS) ;<> 0
StopDrawing()
ProcedureReturn tmpImg
EndIf
EndProcedure
Procedure.i GRAY(iMg.i) ; Ctrl+G
; reduce colors to 256 grayscale
; color weights are R=0.286, G=0.571, B=0.143
Static kb=$FF0000, kg=$00FF00, kr=$0000FF
Protected x,y,d,Ymax,Xmax,lum
Protected tmpImg.i=CopyImage(iMg, #PB_Any)
If IsImage(tmpImg)
StartDrawing(ImageOutput(tmpImg))
Xmax = OutputWidth() - 1
Ymax = OutputHeight() - 1
For y = 0 To Ymax
For x = 0 To Xmax
d = Point(x,y)
lum = ((d & kr)<<1 + (d & kg)>>6 + (d & kb)>>16) / 7
Plot(x,y,lum<<16 | lum<<8 | lum)
Next x
Next y
StopDrawing()
EndIf
ProcedureReturn tmpImg
EndProcedure
;}
I can get image from Database Blob only 22-23 times.
After that procedure doesn't return any value as it reaches maximum.
And handles (got by debugging) returned from GetBlobImg are strange.
As shown below,
GetBlobImg procedure return 8 symbol PB image handle (which seems ok and image applied to mageGadget ) for a while.
31498464
31498704
31498864
.
.
.
31501904
then the ImageHandle is returned 10 symbols (which makes image not shown in Gadget) for a while.
2760892400
2760892560
2760892720
.
,
,
2495609856
2495610016
2495610176
And then these handles again returned 8 Synvols and become OK to load ImageHandle to Window.
353089408
353089568
353089728
353089888
.
.
.
353099808
353099968
353100128
353100288
353100448
353100608