Android Question ScrollView Save as Image

alon

Active Member
Licensed User
Longtime User
Hi everyone,
I am trying to save a scroll view as an image
and the problem is , that the image created is showing only the top view of the scroll,
and I need to create the image of the entire scroll.
I am using the code below for that.
does anyone know what should I do?
should I save every view in the scroll view as an image and then merge it to one image?
or there is a simple way?
Thanks



B4X:
Sub SavViewAsBitmap (aView As View) As Bitmap
Dim b As Bitmap
Dim c As Canvas
b.InitializeMutable(aView.Width, aView.Height *2) ' Initialize mutable bitmap to contain size of aView ...
c.Initialize2(b) ' Get bitmap canvas ...
' Get B4A.Canvas android.graphics.Canvas (Android native type) field
' We need it as native Android type in order to call the "draw" function below ...
Dim args(1) As Object
Dim types(1) As String
Dim r As Reflector
r.Target = c
args(0) = r.GetField("canvas") ' Get android.graphics.Canvas field ...
types(0) = "android.graphics.Canvas"
' Draw aView content onto the bitmap canvas ...
r.Target = aView
r.RunMethod4("draw", args, types)
Return b
End Sub
 

alon

Active Member
Licensed User
Longtime User
Are you passing ScrollView.InnerPanel?
no, I am only passing the scroll view, like shown in the code below
how can I pass it?

B4X:
 Dim bmp As Bitmap
 bmp = SavViewAsBitmap(svJobInfo) ' svJobInfo = ScrollView
 
Upvote 0

alon

Active Member
Licensed User
Longtime User
B4X:
bmp = SaveViewAsBitmap(svJobInfo.Panel)


I have another Issue (I didn't know if to open another thread).
the problem is that after I am saving the return bitmap like this:
B4X:
Dim bmp As Bitmap
bmp = SaveViewAsBitmap(svJobInfo.Panel)
Dim Out As OutputStream
Out = File.OpenOutput(File.DirRootExternal,"ImgScrollView.png", False)
b.WriteToStream (Out, 100, "PNG")
Out.Close
the first time the file is being create everything is good, the problem start when saving again with the same file name,
the file is not replaced I always see the first image I have created, I also tried to delete the file before creating it,
but still I am having the same problem, of seeing the first image that was created.
Bye the way If I am changing the file name before saving it , then it is ok, but I don't want to have a lot of files.
What am I missing here?
 
Upvote 0

alon

Active Member
Licensed User
Longtime User
you see the "wrong" image on your PCs filebrowser?
Try to reconnect device and look again.

Additionally you should start the mediascanner if you want to refresh new files...

No, I see the wrong image in my phone.
which mean the last image is not being erased.
 
Upvote 0

alon

Active Member
Licensed User
Longtime User
did you Plug off the device from usb and connect it AGAIN? Did you chekc the file AFTER you reconnected?

Sure I did that, I am saving the image and then uploading it to my ftp.
and I am always getting the same image
 
Upvote 0

alon

Active Member
Licensed User
Longtime User
Just as an additional check, have you tested this in Release Mode?
I am almost sure I did,
But I will give it another try.
I think that it might be a problem with file.openoutput or maybe with the variable out which I am missing somthing

Thanks
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…