Sub loadImageFromBlob(xSQL1 As SQL, xTable As String, xField As String, xTableID As Long) As Bitmap
Dim Bmp As Bitmap
If xTableID=0 OR xTable.Trim="" OR xField.Trim="" Then Return
Dim imgCursor As Cursor
Dim tempBuffer() As Byte=Null
Dim startblock, lenghtblock As Long
Dim exitLoop As Boolean = False
startblock = 0
Dim blobSize As Long = others.SQL.ExecQuerySingleResult2("SELECT IFNULL(LENGTH(" & xField & "),0) FROM " & xTable & _
" WHERE id = ?", Array As String(xTableID))
If blobSize > 0 Then
lenghtblock = 1000000
'--- Create SubFold per temp images ----------------------------
Dim TargetDir As String=File.DirInternal, TargetFolder As String="images"
If File.ExternalWritable Then TargetDir = File.DirDefaultExternal
If File.Exists(TargetDir, TargetFolder) = False Then File.MakeDir(TargetDir, TargetFolder) '<-- create folder if not exists
Dim out As OutputStream = File.OpenOutput(TargetDir & "/" & TargetFolder, "temp.jpg", False)
'---------------------------------------------------------------
Do While True
If (startblock+lenghtblock) > blobSize Then
lenghtblock=blobSize-startblock+1
exitLoop=True
Else
exitLoop=False
End If
imgCursor = others.SQL.ExecQuery2("SELECT SUBSTR(" & xField & ",?,?) as image FROM " & xTable & _
" WHERE id = ?", Array As String(startblock, lenghtblock, xTableID))
imgCursor.position = 0
tempBuffer = imgCursor.GetBlob("image")
out.WriteBytes(tempBuffer, 0, tempBuffer.Length ) 'lenghtblock)
If exitLoop = True Then Exit
startblock = startblock+lenghtblock
Loop
imgCursor.close
out.Close
Dim InputStream1 As InputStream
InputStream1 = File.OpenInput(TargetDir & "/" & TargetFolder, "temp.jpg")
Dim OutputStream1 As OutputStream
OutputStream1.InitializeToBytesArray(0) '1000)
File.Copy2(InputStream1, OutputStream1)
Dim dataBuffer() As Byte 'declares an empty array
dataBuffer = OutputStream1.ToBytesArray
OutputStream1.Close
If dataBuffer <> Null Then
Dim InputStream1 As InputStream
InputStream1.InitializeFromBytesArray(dataBuffer, 0, dataBuffer.Length) '<-- copy outpustream in InputStream
Bmp.Initialize2(InputStream1) '<-- trasform in BMP
InputStream1.Close
Dim dataBuffer() As Byte = Null 'free buffer
End If
File.Delete(TargetDir & "/" & TargetFolder, "temp.jpg")
Return Bmp
Else
Return Null
End If
End Sub