Android Question Resize and save an image for cache.

Alejandro Moyano

Member
Licensed User
Hi i'm trying to add image cache for an custom control that i made and share here as XUIImageBottom and can't find the reason why its save the full image instead the resize ones.

must.png show.png

I'm implemented the cache using this code:

B4X:
'inizialize and load the icon object
    imgIcon = CreateImageView("imgIcon")
    If ImageFileName <> "" Then
        imgIcon.Height = cmdButton.Height-Margin*2
        imgIcon.Width = cmdButton.Height-Margin*2
        'if cache is true we atempt to use the cache
        Dim image As B4XBitmap
        If vCacheImage = True Then
            Try
                image = objXUI.LoadBitmap(objXUI.DefaultFolder,"cache_"&ControlName&ImageFileName)
                imgIcon.SetBitmap(image) 'fit on the box
            Catch
                Dim out As OutputStream
                out = File.OpenOutput(objXUI.DefaultFolder,"cache_"&ControlName&ImageFileName, False)
                image = objXUI.LoadBitmapResize(File.DirAssets,ImageFileName,imgIcon.Width, imgIcon.Height, True)
                image.WriteToStream(out,100,"PNG")
                out.Close
                imgIcon.SetBitmap(image)
            End Try
        Else
            image = objXUI.LoadBitmapResize(File.DirAssets,ImageFileName,imgIcon.Width, imgIcon.Height, True)
            imgIcon.SetBitmap(image) 'fit on the box
        End If
    Else
        imgIcon.Height = 0
        imgIcon.Width = 0
    End If

I currently use a lot this control, and wish boost the load time implementing image caching.
 

Alejandro Moyano

Member
Licensed User
Hi, @Erel

I think the full image is saved because i see a cropped image in the second launch and must be as was resized to the control size, in the first launch the images are fit to the control an saved as cache images resized on the control size.

I don't use file exist as only in the first launch it will drop to the catch after one run the image is created and it allways will be loaded.

My idea is to have a ductile button useful for mostly everything as i like use many icons, last month i sold an small internal app to sell on the street and i used a lot of images and i'm starting to think if caching the images can boost the load time as in the next version i wanna integrate animated transitions between two icons and can spent more resources as it will resize each time.

Plus am i doing it rigth, i trying to doing on B4X code?

Excuses my english, could be a bit crappy, is not my main language.
 
Upvote 0
Top