Android Question how to save a imageview.background to file?

yhyzhj

Member
I want to know how to save a imageview.bakcground to file.
And I want to know how to save a icon of app to file.
pleae help me!
 
Write exactly what you want to achieve and what you need such a solution for ... Maybe it can be solved in a different way ...
 
Upvote 0
Try this, you can also use GetSafeDirDefaultExternal if you really want to...
 

Attachments

Upvote 0
better to use B4XImageView multi platform

B4X: Copy
Sub Class_Globals
    Private xui As XUI
    Private B4XImageView1 As B4XImageView
End Sub

B4X: Copy
    'Load Image
    B4XImageView1.Bitmap = xui.LoadBitmap(File.DirAssets, "img.jpg")
    B4XImageView1.ResizeMode = "NONE" 'or "FILL"
    B4XImageView1.Update
      
    'Save to file
    SaveBitmapToFile(B4XImageView1.Bitmap, xui.DefaultFolder, "ImageView1.png")

B4X: Copy
Public Sub SaveBitmapToFile(Image As B4XBitmap, DirFolder As String, FileName As String)
    Dim Out As OutputStream
    Out = File.OpenOutput(DirFolder, FileName, False)
    Image.WriteToStream(Out, 100, "PNG")
    Out.Close
End Sub
 
Last edited:
Upvote 0
Write exactly what you want to achieve and what you need such a solution for ... Maybe it can be solved in a different way ...
i just want to write a launcher app. i have got all icon of apps, now need put the icons into gridview. but I use GridView.AddImage("",icon.Bitmap), show dir can not be null. so, i think that must save the icons to files. then i can use GridView.AddImage(dir,imagefile).
 
Upvote 0
sample with BitmapDrawable and icon APP

you APP Application.PackageName

B4X: Copy
    Dim pm As PackageManager
    Dim icon As BitmapDrawable = pm.GetApplicationIcon(Application.PackageName)
    ImageView1.SetBackgroundImage(icon.Bitmap)
    SaveBitmapToFile(ImageView1.Bitmap, xui.DefaultFolder, "myicon.png")

or

B4X: Copy
    Dim pm As PackageManager
    Dim icon As BitmapDrawable = pm.GetApplicationIcon(Application.PackageName)
    ImageView1.Background = icon
    SaveBitmapToFile(ImageView1.Bitmap, xui.DefaultFolder, "myicon.png")
 
Last edited:
Upvote 0
sample with BitmapDrawable and icon APP

you APP Application.PackageName

B4X: Copy
    Dim pm As PackageManager
    Dim icon As BitmapDrawable = pm.GetApplicationIcon(Application.PackageName)
    ImageView1.SetBackgroundImage(icon.Bitmap)
    SaveBitmapToFile(ImageView1.Bitmap, xui.DefaultFolder, "myicon.png")

or

B4X: Copy
    Dim pm As PackageManager
    Dim icon As BitmapDrawable = pm.GetApplicationIcon(Application.PackageName)
    ImageView1.Background = icon
    SaveBitmapToFile(ImageView1.Bitmap, xui.DefaultFolder, "myicon.png")

thank you! it works!
if I want to add icons into GridView, how to do?
 
Upvote 0
Back
Top