B4i Library cviZoomableImageView

B4X:
'based on ImageZoom library :https://www.b4x.com/android/forum/threads/zoomable-imageview.55185/
'version:1.0
'usage:1.add by designer
Private cvzi As cviZoomableImageView
'do not suggest set minscale -_^
cvzi.MaxScale=3
 'at last set the bitmap
cvzi.Bitmap=newbmp
 

Attachments

  • cviZoomableImageView.bas
    7 KB · Views: 43

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
Hi,
I have been using this library, but I am having a slight problem. When the max zoom is set higher than about 3 and then you expand the image, part of the image is clipped.
The clipping gets worse the more the image is zoomed.

I have a sample program that demonstrates the problem.

Any ideas why this is happening?

Thanks

Andrew
 

Attachments

  • cviZoomable.zip
    15.7 KB · Views: 20

Daniel Uribe

Member
Licensed User
Longtime User
Hi,
I have been using this library, but I am having a slight problem. When the max zoom is set higher than about 3 and then you expand the image, part of the image is clipped.
The clipping gets worse the more the image is zoomed.

I have a sample program that demonstrates the problem.

Any ideas why this is happening?

Thanks

Andrew
You can convert the image selected by user with specific dimensions, using this way worked perfect for me (in cases where you use the iMedia library to select user images as an example):

B4X:
Sub Cam_Complete (Success As Boolean, Image As Bitmap, VideoPath As String)
    If Success Then
        Dim esvideo As Boolean

        If VideoPath = Null Then
            esvideo = False
        Else if VideoPath.Contains("/") Then
            esvideo = True
            VideoPath = Null
        End If

        If esvideo = True Then
            HD.ToastMessageShow("Just images",False)
        Else if esvideo = False Then

        SaveBitmap(CreateScaledBitmap2(Image,721,1280),"imageselected.png",File.DirDocuments,500) 'THIS IS
            
                pgFoto.Initialize("pgFoto")
                pgFoto.RootPanel.Color = Colors.Transparent
                pgFoto.RootPanel.LoadLayout("pgFoto")
                pgFoto.RootPanel.Alpha = 1
                imgZoom.GetBase.SetBorder(0,Colors.Transparent,0)
                imgZoom.GetBase.Color = Colors.Transparent
                imgZoom.Bitmap = LoadBitmap(File.DirDocuments,"imagemodificable.png")
                imgZoom.MaxScale = 100%x
                Main.NavControl.ShowPage(pgFoto)
    End If
End Sub

Sub CreateScaledBitmap (Image As Bitmap, Width As Int, Height As Int) As Bitmap
    Dim PhotoCanvas As Canvas
    Dim PhotoPanel As Panel
    Dim PhotoView As ImageView
    Dim NewImage As Bitmap

    PhotoPanel.Initialize("")
    PhotoPanel.Width = Width / 2
    PhotoPanel.Height = Height / 2

    PhotoView.Initialize("")
    PhotoView.Bitmap = Image
    PhotoPanel.AddView(PhotoView,0,0,Width / 2,Height / 2)

    PhotoCanvas.Initialize(PhotoPanel)
    NewImage = PhotoCanvas.CreateBitmap

    Return NewImage
End Sub

Sub SaveBitmap (Image As Bitmap, Filename As String, Dir As String, Quality As Int) As Boolean
    Dim Result As Boolean= True
    Dim out As OutputStream = File.OpenOutput(Dir, Filename, False)
    Dim data() As Byte = GetByteFromBitmap(Image, Quality)
    Try
        out.WriteBytes(data, 0, data.Length)
    Catch
        Result = False
    End Try
    out.Close
    Return Result
End Sub

Sub GetByteFromBitmap(img As Bitmap, Quality As Int) As Byte()
    Dim out As OutputStream
    Dim data() As Byte
    out.InitializeToBytesArray(1)
    img.WriteToStream(out,Quality,"PNG")
    data = out.ToBytesArray
    out.Close
    Return data
End Sub


if you like, you can use the attached layout that I did based on the one that uses whatsapp to resize the image, just subtract the events and done.
 

Attachments

  • pgFoto.zip
    6.8 KB · Views: 13
Last edited:
Top