Italian Caricare una gif in b4i

ken87

Active Member
Licensed User
Longtime User
Buonasera,
Per caricare una gif in un panello ho utilizzato
B4X:
WebView1.LoadUrl("file://" & File.Combine(File.DirAssets, "10.gif"))

Il componente l'ho messo utilizzando la grafica della pagina

Ora il box che contiene la gif la visualizzo bianco e la gif la nette in altro .
Se volessi centrare la gif e uno sfondo colorato come faccio
Ho utilizzato la proprieta bakground con un colore ma si vede sempre bianco e sempre nella parte alra allego la foto.
Grazie mille
 

Attachments

  • vedi.jpg
    vedi.jpg
    11.6 KB · Views: 161

GIS

Well-Known Member
Licensed User
perchè non usi ImageView cosi la puoi centrare come vuoi
 

ken87

Active Member
Licensed User
Longtime User
Ciao supporta le gif animate?

Ho ache tentato
B4X:
WebView1.Color = Colors.Transparent
ma nulla .
Ora provo
 

GIS

Well-Known Member
Licensed User
Libreria Gifdecoder io so che l'ho utilizzata in una mia app

questo è il modulo class che ho utilizzato
B4X:
'Custom View class
#Event: ExampleEvent (Value As Int)
#DesignerProperty: Key: BooleanExample, DisplayName: Boolean Example, FieldType: Boolean, DefaultValue: True, Description: Example of a boolean property.
#DesignerProperty: Key: IntExample, DisplayName: Int Example, FieldType: Int, DefaultValue: 10, MinRange: 0, MaxRange: 100, Description: Note that MinRange and MaxRange are optional.
#DesignerProperty: Key: StringWithListExample, DisplayName: String With List, FieldType: String, DefaultValue: Sunday, List: Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday
#DesignerProperty: Key: StringExample, DisplayName: String Example, FieldType: String, DefaultValue: Text
#DesignerProperty: Key: ColorExample, DisplayName: Color Example, FieldType: Color, DefaultValue: 0xFFCFDCDC, Description: You can use the built-in color picker to find the color values.
#DesignerProperty: Key: DefaultColorExample, DisplayName: Default Color Example, FieldType: Color, DefaultValue: Null, Description: Setting the default value to Null means that a nullable field will be displayed.
Sub Class_Globals
    Private mEventName As String 'ignore
    Private mCallBack As Object 'ignore
    Private mBase As Panel
    Private Const DefaultColorConstant As Int = -984833 'ignore
    Private WorkIndex As Int
    Private BDGravity As Int
    Private bitmaps As List
    Type BitmapAndDelay (bmp As Bitmap, Delay As Int)
End Sub

Public Sub Initialize (Callback As Object, EventName As String)
    mEventName = EventName
    mCallBack = Callback
End Sub

Public Sub DesignerCreateView (Base As Panel, Lbl As Label, Props As Map)
    mBase = Base
    mBase.Visible = False
End Sub

Public Sub SetGif (Dir As String, FileName As String)
    If Dir = File.DirAssets Then
        File.Copy(File.DirAssets, FileName, File.DirInternal, FileName)
        Dir = File.DirInternal
    End If
    Dim path As String = File.Combine(Dir, FileName)
    If Main.GifsCache.IsInitialized = False Then Main.GifsCache.Initialize
    If Main.GifsCache.ContainsKey(path) Then
        bitmaps = Main.GifsCache.Get(path)
    Else
        Dim gd As GifDecoder
        gd.Load(Dir, FileName)
        bitmaps.Initialize
        For i = 0 To gd.FrameCount - 1
            Dim bd As BitmapAndDelay
            bd.Initialize
            bd.bmp = gd.Frame(i)
            bd.Delay = gd.Delay(i)
            bitmaps.Add(bd)
        Next
        Main.GifsCache.Put(path, bitmaps)
    End If

    Dim FirstFrame As BitmapAndDelay = bitmaps.Get(0)
    Dim FirstBmp As Bitmap = FirstFrame.bmp
    If FirstBmp.Width < mBase.Width Or FirstBmp.Height < mBase.Height Then
        BDGravity = Gravity.CENTER
    Else
        BDGravity = Gravity.FILL
    End If
  
End Sub

Public Sub Start
    mBase.Visible = True
    WorkIndex = WorkIndex + 1
    ShowImpl(WorkIndex)
End Sub

Public Sub Stop
    mBase.Visible = False
    WorkIndex = WorkIndex + 1
End Sub

Public Sub CallFromResume
    If mBase.Visible Then Start
End Sub

Private Sub ShowImpl(MyWorkIndex As Int)
    Dim FrameIndex As Int = 0
    Do While MyWorkIndex = WorkIndex
        FrameIndex = (FrameIndex + 1) Mod bitmaps.Size
        Dim bdrawable As BitmapDrawable
        Dim bd As BitmapAndDelay = bitmaps.Get(FrameIndex)
        bdrawable.Initialize(bd.bmp)
        bdrawable.Gravity = BDGravity
        mBase.Background = bdrawable
        Sleep(bd.Delay)
    Loop
End Sub

Public Sub GetBase As Panel
    Return mBase

Loading.SetGif(File.DirAssets, "loading.gif")

Loading.Stop


customView per il designer sono andato a vedere non mi ricordavo
 

ken87

Active Member
Licensed User
Longtime User
Caio la libreia penso che sia per b4a perchè b4a tutto ok su b4i mi da un po di errori
tipo
B4X:
File.Copy(File.DirAssets, FileName, File.DirInternal, FileName)
Membro sconosciuto
B4X:
BDGravity = Gravity.CENTER
Variabile Gravity non dichiarata
allego sotto
Grazie mille lo stesso
 

Attachments

  • errore1.jpg
    errore1.jpg
    366.4 KB · Views: 167

ken87

Active Member
Licensed User
Longtime User
Cerco di convertirlo ci provo.
se riesco posto.. se hai una soluzione posta
Grazie mille
 
Top