Change Snapped Image FILENAME

MODERN TALKING

Active Member
Licensed User
Longtime User
Hi guys,

USD 10 to tell me how to do this EASY PEASY thing:

I take a Picture with Smartphone Camera and it Auto-Saves it in Images Folder.

DAS MISSION: How do I CHANGE THE FILENAME of this Picture which I just snapped?

Danke!
 

DonManfred

Expert
Licensed User
Longtime User
B4X:
Sub Camera1_PictureTaken (Data() As Byte)
    Dim filename As String = "1.jpg"
    Dim dir As String = File.DirRootExternal
    camEx.SavePictureToFile(Data, dir, filename)

or

B4X:
Sub Camera1_PictureTaken (Data() As Byte)
    Dim filename As String = "1.jpg"
    Dim dir As String = File.DirRootExternal
   
    Dim instr As InputStream
    instr.InitializeFromBytesArray(Data,0,Data.Length)
   
    Dim bmp As Bitmap
    bmp.Initialize2(instr)

   
  Dim out As OutputStream
  out = File.OpenOutput(File.DirRootExternal, filename, False)
  bmp.WriteToStream(out, 100, "JPEG")
  out.Close
 

MODERN TALKING

Active Member
Licensed User
Longtime User
Didn't work Manfred.

Please guide me.

I take a Picture with built-in ORIGINAL Smartphone Camera - NOT CAMERAEX Library.
 

MODERN TALKING

Active Member
Licensed User
Longtime User
Filename of the Picture in Images Folder is "20160327_223414.jpg"

How to change it to "test.jpg"?
 

DonManfred

Expert
Licensed User
Longtime User
B4X:
Sub Camera1_PictureTaken (Data() As Byte)
    Dim filename As String = "1.jpg"
    Dim dir As String = File.DirRootExternal

    camera1.StartPreview
    Dim out As OutputStream
    out = File.OpenOutput(dir, filename, False)
    out.WriteBytes(Data, 0, Data.Length)
    out.Close
    ToastMessageShow("Image saved: " & File.Combine(dir, filename), True)
    btnTakePicture.Enabled = True
End Sub
 

Attachments

  • CameraEx.zip
    6 KB · Views: 203

MODERN TALKING

Active Member
Licensed User
Longtime User
Samsung Smartphone has ORIGINAL CAMERA ICON.

I click on it and take a Picture.

It saves as FILENAME <DATE_TIME.jpg>

I wanna CHANGE this FILENAME to "test.jpg"

That's it.
 

MODERN TALKING

Active Member
Licensed User
Longtime User
Which means:

1. I switch on my App.
2. I switch on the ORIGINAL SAMSUNG CAMERA ICON.
3. I take a Picture.
4. My App CHANGES THE FILENAME of the snapped Picture.

That's it.
 

DonManfred

Expert
Licensed User
Longtime User
4. My App CHANGES THE FILENAME of the snapped Picture.
I dont know if the original camera app sends an broadcast for the new picture or something similar.
So, i don´t know how to capture the filename of the picture just taken.
 

strat

Active Member
Licensed User
Longtime User
I think, no need to pay for helps. Helps are not related to getting money, it is related to konowledge, experience and willingness.


There may be an approach from picture filename format. Original camera app saves to file "YYYYMMDD_HHMMSS.jpg".
We can suppose that the biggest filename number is the last file.

You can do it step by step:
- Your app get all pictures into the list at firts run. Then, it keeps on run in the background.
- You take picture with original camera app. A new picture will be saved.
- Your app checks the new file that is not in the list, finds and renames. You can search the biggest number in the filename. According to the filename format, biggest number is the newest picture.

I can help you to write this sample if you convinced to the good idea.
 

MODERN TALKING

Active Member
Licensed User
Longtime User
THANK YOU SO MUCH Strat.

You are right about the payments - but just a motivator. Small 'donation' - not really payment for job.

Your idea is FANTASTIC - where do we begin?
 

MODERN TALKING

Active Member
Licensed User
Longtime User
Dim A,B,C,D As String
A = $"$DateTime{DateTime.Now}"$
A = A.Replace(":","")
B = A.SubString2(6,10) & A.SubString2(0,2) & A.SubString2(3,5)

B = B & "_" & A.SubString2(11,15)

Activity.Title = B

For I = 0 To 59
If I < 10 Then
D = "0" & I
Else
D = I
End If
C = B & D & ".jpg"
If File.Exists(File.DirRootExternal, C) Then
Activity.Title = C
Else
Activity.Title = "Error"
End If
Next
 
Top