How to display a .gif in an ImageView

Azhar

Active Member
Licensed User
Longtime User
Hi

I'm having trouble trying to display a plain non animated .gif in an imageView place holder with the code below. The file exists and the filename checks out good. All I get is a blank white square on the display where the image should be.

Can anyone let me know where I'm going wrong?

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim label7, label8, label9, label10, label11 As Label
Dim IVmoon As ImageView
Dim bitmapImage As Bitmap

End Sub

Sub Activity_Create(FirstTime As Boolean)

Activity.LoadLayout("moonDisplayLayout")

label10.Text = Main.moonReturnedLabels.label1 '% illuminated
label7.Text = Main.moonReturnedLabels.label2 'moon Age
label11.Text = Main.moonReturnedLabels.label3 'phase name
label8.Text = Main.moonReturnedLabels.label4 'moon rise
label9.Text = Main.moonReturnedLabels.label5 'moon set

Dim moonAge As Int, moonFilename As String
moonAge = s.Val(s.Left(Main.moonReturnedLabels.label2,2))
IVmoon.Initialize("")
moonFilename = "moon" & moonAge & ".gif"

bitmapImage.Initialize(File.DirAssets,moonFilename)
IVmoon.Bitmap = bitmapImage



End Sub

a typical filename should be 'moon17.gif'

Thanks,

Azhar
 

Azhar

Active Member
Licensed User
Longtime User
Add:
B4X:
IVmoon.Gravity = Gravity.Fill

Hi

Thanks.

I've inserted:

IVmoon.Gravity = Gravity.FILL
IVmoon.Bitmap = bitmapImage

and it still doesn't display. If I load the .gif directly into the container in designer it displays no problem. Just can't get it to display from the code.
 
Upvote 0

Azhar

Active Member
Licensed User
Longtime User
Hi

This is really strange for something which shouldn't be an issue.
I initially assigned the gravity setting after the bitmap and that didn't work either then swapped them around to see if that made a difference.

The code extract is as below:

Azhar
----------------------------------------------------

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim label7, label8, label9, label10, label11 As Label
Dim IVmoon As ImageView
Dim bitmapImage As Bitmap

End Sub

Sub Activity_Create(FirstTime As Boolean)

Activity.LoadLayout("moonDisplayLayout")

label10.Text = Main.moonReturnedLabels.label1 '% illuminated
label7.Text = Main.moonReturnedLabels.label2 'moon Age
label11.Text = Main.moonReturnedLabels.label3 'phase name
label8.Text = Main.moonReturnedLabels.label4 'moon rise
label9.Text = Main.moonReturnedLabels.label5 'moon set

Dim moonAge As Int, moonFilename As String
moonAge = s.Val(s.Left(Main.moonReturnedLabels.label2,2))
IVmoon.Initialize("")
moonFilename = "moon" & moonAge & ".gif"

bitmapImage.Initialize(File.DirAssets, moonFilename)
IVmoon.Bitmap = bitmapImage
IVmoon.Gravity = Gravity.FILL

End Sub
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
One thing I can say is that certain image files are not compatible with Android. Last week I spent about hours trying to find out why a particular JPEG file was not being displayed on Imageview. Finally I converted it to PNG and it worked.

When you save an image file in an image viewer like Irfanview or ACDSee, there are some settings that can be ticked and unticked and I think enabling some of them makes the image incompatible with Android. So I suggest you convert the gif image to another format and try again.
 
Upvote 0

Azhar

Active Member
Licensed User
Longtime User
Hi

Finally at last I found the problem!

Since the imageview was created in designer, I only had to comment out this line:

IVmoon.Initialize("")

Then everything worked!

Azhar
 
Upvote 0
Top