iOS Question Resize Image Sub

Discussion in 'iOS Questions' started by Luiz Fernando Orlandini, Feb 19, 2015.

  1. Luiz Fernando Orlandini

    Luiz Fernando Orlandini Active Member Licensed User

    Hi All.

    I'm trying to use this code snippet to resize an image, but I don't have success. What's am I doing wrong?

    Code:
    Public Sub loadPhoto(photo As StringAs Bitmap
        
    Try
            
    Dim su As StringUtils
            
    Dim i As InputStream
            i.InitializeFromBytesArray(su.DecodeBase64(photo), 
    0, su.DecodeBase64(photo).Length)
            
    Dim p As Bitmap
            p.Initialize2(i)
            
    Return p
        
    Catch
            
    Dim p As Bitmap
            p.Initialize(
    File.DirAssets, "avatar-scholastic.png")
            
    Return p       
        
    End Try
    End Sub


    Public Sub ResizeImage (Image As String, Scale As Int) As Bitmap
        
    Dim PhotoCanvas As Canvas
        
    Dim PhotoPanel As Panel
        
    Dim PhotoView As ImageView
        
    Dim NewImage As Bitmap
     
        PhotoView.Initialize(
    "")
        PhotoView.Bitmap = loadPhoto(
    Image)

        PhotoPanel.Initialize(
    "")
        PhotoPanel.Height = 
    500
        PhotoPanel.Width = 
    500
        PhotoPanel.SetBorder(
    0Colors.Transparent, PhotoView.Width/2)
     
        PhotoPanel.AddView(PhotoView,
    0,0, PhotoPanel.Width / Scale, PhotoPanel.Height / Scale)

        PhotoCanvas.Initialize(PhotoPanel)
        NewImage = PhotoCanvas.CreateBitmap
     
        
    Return NewImage
    End Sub
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    This is not the correct code. Do you want to resize and save the image or only show it?
     
  3. Luiz Fernando Orlandini

    Luiz Fernando Orlandini Active Member Licensed User

    I have both requirements in different points of APP.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    You can use this code to resize an image:
    Code:
    Sub ResizeBitmap(bmp As Bitmap, scale As Float) As Bitmap
       
    Dim img As ImageView
       img.Initialize(
    "")
       img.Width = bmp.Width * scale
       img.Height = bmp.Height * scale
       
    Dim cvs As Canvas
       cvs.Initialize(img)
       cvs.DrawBitmap(bmp, cvs.TargetRect)
       
    Dim res As Bitmap = cvs.CreateBitmap
       cvs.Release
       
    Return res
    End Sub
     
    Last edited: Mar 15, 2016
    Samplatiner and Peter Simpson like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice