Saving a Picture

Biscuit

Member
Licensed User
Longtime User
Hi

I am trying to save a picture to the device but I'm having a couple of issues. I'm using this code to save the picture:

Code: Copy
Dim dlg As FileDialog
Dim response As Int

If File.ExternalWritable Then
   dlg.FilePath = File.DirDefaultExternal
End If

response = dlg.Show(gAppName, "Save", "Cancel", "", Null)

If response = DialogResponse.POSITIVE Then
   If dlg.ChosenName <> "" Then
      Dim out As OutputStream
      out = File.OpenOutput(dlg.FilePath, dlg.ChosenName & ".jpg", False)
      mFrontCanvas.Bitmap.WriteToStream(out, 100, "JPEG")
      out.Flush
      out.Close

      ToastMessageShow("Picture saved", True)
   Else
      ToastMessageShow("No filename entered", True)
   End If
End If

The first is using the File Dialog. At first, this is the way I wanted it to work but I think I'd prefer to just save the pictures directly to the standard photos / pictures folder and not use the dialog. Is there a constant for this or a way of finding out the path to the photo folder without hard coding it?

The second issue is if I navigate to the photo folder (under 'sdcard\photo') using the dialog then I can save the image there instead which is fine. However, the problem is I then I want to see the saved picture in the gallery but the saved pictures don't show unless I reboot the phone? Is there some message or method I need to call in order to get the pictures to show up in the gallery?

I'm initialising the content chooser in Activity_Create like this:
Code: Copy
mContentChooser.Initialize("mContentChooser")

and then invoking it based on a button click like this:
Code: Copy
mContentChooser.Show("image/*", "Choose Picture")

Thanks
 
Hi,

What gallery are you talking about.
The standard gallery from your phone or the gallery that you have
made with the designer.

Look at my example in the tutorial section with the title:
'Imageview related with sdcard getting images"

You use an galleryview instead to get a picture.

Maybe it helps.

Asmoro
 
Last edited:
Upvote 0
I'm talking about the standard gallery from my phone which is shown using:
mContentChooser.Show("image/*", "Choose Picture")

It just seems like it needs to be told to refresh its index or something...
 
Upvote 0
Here is an example that does what you need:
Code: Copy
Sub Activity_Create(FirstTime As Boolean)
    'create image
    Dim b As Bitmap
    b.InitializeMutable(200, 200)
    Dim c As Canvas
    c.Initialize2(b)
    c.DrawCircle(100, 100, 50, Colors.Red, True, 0)

    'save image to file
    Dim out As OutputStream
    out = File.OpenOutput(File.DirRootExternal, "pictures/1.jpg", False)
    b.WriteToStream(out, 100, "JPEG")
    out.Close

    'send the intent that asks the media scanner to scan the file
    Dim i As Intent
    i.Initialize("android.intent.action.MEDIA_SCANNER_SCAN_FILE", _
        "file://" & File.Combine(File.DirRootExternal, "pictures/1.jpg"))
    Dim p As Phone
    p.SendBroadcastIntent(i)
End Sub

It requires Basic4android v1.6 which will be released next week.
 
Upvote 0
Scan all files

I have more mp3 files in "File.DirRootExternal".
how can I initialize "MEDIA_SCANNER_SCAN_FILE" for all mp3 files?:(
 
Upvote 0
Save image in mssql database

Dear

Please help me to save image to ms sql database. the database is available in web server. i am saving data through sql query like.

a.Query("INSERT INTO TAB_DAY_PLANNER (EMPID, Date_ID, DP_DATE, TIME_FROM, TIME_TO, PLANNED_PLACE, PLANNED_INSTITU, PLANNED_WITH, worktype, remark) VALUES("& Password.Text &", 101, '" & datetxt.Text & "', '" & frmbtn.Text & "', '" & tobtn.Text & "', '" & Spinner1.SelectedItem & "', '" & Spinner3.SelectedItem & "', '" & Spinner2.SelectedItem & "', '" & spLanguage.SelectedItem & "', '" & Remark.Text & "' )")

Pl help me to save image.

Thanks
 
Upvote 0
Back
Top