Android Question android.graphics.Bitmap.setDensity(int)

Scantech

Well-Known Member
Licensed User
Longtime User
I use this code to load .png

B4X:
MediaManager.SetMediaWithExtra(pnlCLV.GetView(x).GetView(0), GetIconLink, "image/*", CreateMap(MediaManager.REQUEST_CALLBACK: Me))

In SMM_MediaReady i do this

B4X:
                Dim Out As OutputStream
                Out = File.OpenOutput(File.DirInternal, Starter.SelectedFolder & WhatFileName, False)
                Media.Media.As(B4XBitmap).WriteToStream(Out, 50, "PNG")
                Out.Close

Out of 200 png few of them gets this error when i load the png file using this

B4X:
 MediaManager.SetMediaFromFile(pnlCLV.GetView(x).GetView(0), File.DirInternal, Starter.SelectedFolder & WhatFileName, "image/*", Null)

error code
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.graphics.Bitmap.setDensity(int)' on a null object reference

When i download the png with Http job and save the job.GetInputStream. it loads perfectly fine.
 

Scantech

Well-Known Member
Licensed User
Longtime User
What is the output of:
B4X:
Log("bmp: " & Media.Media)

BTW, what is the purpose of this code? Why load the same image twice?

Maybe i dont understand the purpose of the MediaManager.SetMediaWithExtra? It is making a http request which causes data usage if i keep repeating the code. Therefore, I save the file so i can show the image with MediaManager.SetMediaFromFile.
 
Last edited:
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User
Here is another one

(SMM_MediaReady)
bmp: android.graphics.Bitmap@e879bf6
WULCjJZ.png
SMM_READY ERROR: (IllegalStateException) java.lang.IllegalStateException: Can't compress a recycled bitmap
test image
https: //i.imgur.com/WULCjJZ.png
remove spaces after https:
 
Last edited:
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User
i noticed the Sub SMM_MediaReady get rapidly triggered and may causing issues with writetostream? I get more errors with scrolling fast.
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…