Saving an image from an imageview

buttons

Member
Licensed User
Longtime User
I have a photo set as my phone background but unfortunately the original photo is corrupt. I used the LiveWallpaper library to retrieve and show it in an imageview using the following code:

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim lp As LiveWallpaper

Dim ImageView1 As ImageView
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("main")
Dim dr As BitmapDrawable
dr=lp.Drawable
ImageView1.Background=dr

End Sub

Is there a way to now save this as a JPG onto my SDCard, or alternatively does anyone know how I can get a copy of the stored background by another method? Many thanks.
:)
 

pluton

Active Member
Licensed User
Longtime User
I don't know if I understand question but this is how I Copy image to SD and do Set As Wallpaper

B4X:
Sub copysd_click
   Dim out As OutputStream
   out = File.OpenOutput(File.DirRootExternal, "photo.jpg", False)
   fotka.WriteToStream(out,100,"JPEG")
   out.Close
   ToastMessageShow("Photo.jpg saved to root folder.",False)
   
   
End Sub
Sub setas_click
   SetWallPaper(fotka)
   
End Sub
Sub SetWallPaper(Bmp As Bitmap)
   Dim r As Reflector
   r.Target = r.RunStaticMethod("android.app.WallpaperManager", "getInstance", _
      Array As Object(r.GetContext), Array As String("android.content.Context"))
   r.RunMethod4("setBitmap", Array As Object(Bmp), Array As String("android.graphics.Bitmap"))
   ToastMessageShow("Wallpaper added successfully.",False)
End Sub
 
Upvote 0

buttons

Member
Licensed User
Longtime User
thanks

:)Thanks pluton, that was enough to allow me to change my code to:

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim lp As LiveWallpaper

Dim ImageView1 As ImageView
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("main")
Dim dr As BitmapDrawable
Dim dr2 As Bitmap
dr=lp.Drawable
dr2=dr.Bitmap
ImageView1.Background=dr
Dim out As OutputStream
out = File.OpenOutput(File.DirRootExternal, "photo.jpg", False)
dr2.WriteToStream(out,100,"JPEG")
out.Close

End Sub

Which worked. Thanks, photo recovered!:)
 
Upvote 0

Yeshua

Member
Licensed User
Longtime User
How to save imageview as photo to sd?

B4X:
Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim img1 As ImageView
   Dim bmpImage As Bitmap
   Dim Canvas1 As Canvas
   Dim Button1 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("sd1")
      
   
End Sub


Sub Button1_Click
   Dim out As OutputStream
   Canvas1.Initialize2(bmpImage)
   img1.Bitmap=bmpImage
   out = File.OpenOutput(File.DirRootExternal, "IDPhoto.jpg", False)
   bmpImage.WriteToStream(out,100,"JPEG")
   out.Close
   
End Sub

:sign0085:please!!
 
Upvote 0
Top