Android Question Show picture in imageview

Blue.Sky

Active Member
Licensed User
Longtime User
Hi
I have a rss reader that load picture in imageview
I have a problem
Any picture is different sizse,example 320x430 or 800x420
Now when i show it in imageview,if gravity is fill so picture bad shown
if gravity center,the big picture is over than imageview
How i show any picture in imageview with different size?
 

Ohanian

Active Member
Licensed User
Longtime User
Hi,

try this :
B4X:
ImageView.Gravity = Bit.OR(Gravity.CENTER, Gravity.FILL)
 
Upvote 0

eurojam

Well-Known Member
Licensed User
Longtime User
You should calculate the aspect ratio of the image and then resize the imageview.
 
Upvote 0

eurojam

Well-Known Member
Licensed User
Longtime User
just coded not tested, but something like this
B4X:
    Dim b As Bitmap
    Dim bW, bH As Int 'Imagesize
    Dim a As Double
    Dim iView As ImageView
    b.Initialize(File.DirAssets,"test.png")
    bW = b.Width
    bH = b.Height
    a = bH/bW 'aspect factor
    iView.Initialize("iV")
    Activity.AddView(iView,0,0, 100dip, a*100dip)  'width is fix and height is calculated with aspect
    iView.Bitmap=b
 
Upvote 0

Ohanian

Active Member
Licensed User
Longtime User
Hi,

B4X:
    Dim bmpImage As Bitmap
    Dim imgImage As ImageView   
    Dim bmpEx As BitmapExtended
    Dim LayoutVal As LayoutValues

    LayoutVal = GetDeviceLayoutValues 
   
    bmpImage.InitializeSample(File.DirAssets, "image.jpg", LayoutVal.Width, LayoutVal.Height)
               
    Dim dScale As Double
    dScale = (bmpEx.getHeight(bmpImage) * 100) / bmpEx.getWidth(bmpImage)
    dScale = dScale / 100

    imgImage.Initialize("")
    imgImage.Gravity = Bit.OR(Gravity.CENTER, Gravity.FILL)
    imgImage.Bitmap = bmpImage
   
    Activity.AddView(imgImage, 0, 0, 100%x, (100%x * dScale))
 
Upvote 0

Blue.Sky

Active Member
Licensed User
Longtime User
Hi,

B4X:
    Dim bmpImage As Bitmap
    Dim imgImage As ImageView  
    Dim bmpEx As BitmapExtended
    Dim LayoutVal As LayoutValues

    LayoutVal = GetDeviceLayoutValues
  
    bmpImage.InitializeSample(File.DirAssets, "image.jpg", LayoutVal.Width, LayoutVal.Height)
              
    Dim dScale As Double
    dScale = (bmpEx.getHeight(bmpImage) * 100) / bmpEx.getWidth(bmpImage)
    dScale = dScale / 100

    imgImage.Initialize("")
    imgImage.Gravity = Bit.OR(Gravity.CENTER, Gravity.FILL)
    imgImage.Bitmap = bmpImage
  
    Activity.AddView(imgImage, 0, 0, 100%x, (100%x * dScale))
Thank you.
I added Imageview already with size 200 and 400
I force use imageview with size 200 and 400 because UI designed.
How use "imgImage, 0, 0, 100%x, (100%x * dScale)" for bitmap?
 
Upvote 0

Blue.Sky

Active Member
Licensed User
Longtime User
It's Solved.
I use Picaso in my library.
It is good library for center or resize or crop picture in imageview
 
Upvote 0
Top