Android Question Does any example for taking Photo and saving into table .db?

Itila Tumer

Active Member
Licensed User
Longtime User
Hi
I have blob type database which is persons.db and body table. I can read the image view . but I want to use a Cam . And saving in persons.db as a BLOB . Are there any exapmle ??
Thanks
 

mangojack

Expert
Licensed User
Longtime User
Here is a small example project to read and write image to db .. the db and table names will differ.
 

Attachments

  • ImageDB Example.zip
    56.4 KB · Views: 194
Upvote 0

mangojack

Expert
Licensed User
Longtime User
There should be no problem. Maybe see this tutorial Take pictures with internal Camera ...

Once you have saved the picture you can then write it to the db. You could probably save it direct to db, but have not worked with this.
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
the code in 'Sub WriteBlob' in the ImageDB Example (post #2).
 
Upvote 0

Itila Tumer

Active Member
Licensed User
Longtime User
B4X:
Sub UpdateSelectedItem
    Dim Query As String
    Dim Curs As Cursor
Dim Buffer() As Byte
  Dim IpSt As InputStream
    Dim Bitmap1 As Bitmap

    Try                                                                                     
    Query = "SELECT FirstName, LastName, ID, Boy, Resim FROM persons  INNER JOIN body ON persons.ID = body.IDbody WHERE  ID  = " & IDList.Get(CurrentIndex)
    Curs = SQL1.ExecQuery(Query)
    For i=0 To Curs.RowCount-1
    Curs.Position = i
    lblSelectedItem.Text = Curs.GetString("FirstName") & " " & Curs.GetString("Boy") & " ID = " & Curs.GetString("ID")
    Buffer = Curs.GetBlob("Resim")
      IpSt.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
      Bitmap1.Initialize2(IpSt)
      IpSt.Close
      ImageView1.SetBackgroundImage(Bitmap1)
    Next
    Curs.Close
    Catch
    'Log(LastException)
    Msgbox ("No Match!","")
    End Try


End Sub
:(I tried all day but It is hart in my oppinion. I never did before. So I did Failed. Please littel help

I could read from persons.db kind of Sub Method. But After I shot a Photo . how can INSERT INTO DB with ID
 
Last edited:
Upvote 0

Itila Tumer

Active Member
Licensed User
Longtime User
I also tried to benefit from that. I think I should change this


B4X:
Sub InsertBlob
    'convert the image file to a bytes array
    Dim InputStream1 As InputStream
    InputStream1 = File.OpenInput(File.DirAssets, "smiley.gif")
    Dim OutputStream1 As OutputStream
    OutputStream1.InitializeToBytesArray(1000)
    File.Copy2(InputStream1, OutputStream1)
    Dim Buffer() As Byte 'declares an empty array
    Buffer = OutputStream1.ToBytesArray
  
    'write the image to the database
    SQL1.ExecNonQuery2("INSERT INTO table2 VALUES('smiley', ?)", Array As Object(Buffer))
End Sub
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Itila .. hopefully someone can solve problem. I will return on weekend , if your problem is not solved I will attempt to help you. ;)
 
Upvote 0

Itila Tumer

Active Member
Licensed User
Longtime User
Cheers. No problem, I 'll try to get photos from galery and send to (INSERT) . db . That is my new work.
Thanks for answering
 
Upvote 0
Top