B4A Library Library Resize Image 1.1

Discussion in 'Additional libraries, classes and official updates' started by MarcoRome, Mar 21, 2015.

  1. MarcoRome

    MarcoRome Expert Licensed User

    This library Resize a picture ( Height / Width ) and you can save the same in jpeg or png.
    In this Version ( 1.1 ) this resize is possible for files on local (Ex. DireRoorExternal ) and remote ( Ex. http://www.example.com/test.jpg ), plus you can use the parameter "Ratio"
    ResizePicture
    Version:
    1.1

    Screenshot 2015-03-22 11.43.05.png

    ResizePicture
    Author:
    DevilApp
    Version: 1.1
    • ResizePicture
      Methods:
      • resize (pathSource As String, imgSource As String, w As Int, h As Int, pathDestiny As String, imgDestiny As String, format As String, Ratio As String)
        Resize Image
        pathSource = Path where is original Image
        imgSource = Name Image original
        w = Width
        h = Height
        pathDestiny = Path where you want put new Image
        imgDestiny = Name Image new
        format = "png" or "jpeg"
        ratio = "yes" if you want maintaing its aspect ratio, otherwise "no" and resize your w and h
        Example:<code>
        Dim pic As ResizePicture
        File.Copy(File.DirAssets, "test.jpg",File.DirRootExternal,"test.jpg")
        Dim nomepath As String = File.DirRootExternal
        pic.resize( nomepath, "test.jpg", 600, 400, nomepath, "vedi","jpeg", "yes")</code>
      • resizeUrl (pathSourceUrl As String, imgSource As String, w As Int, h As Int, pathDestiny As String, imgDestiny As String, format As String, Ratio As String)
        Resize and Copy Image from URL to Destiny ;) - Joke NJDude
        pathSourceUrl = URL where is original Image
        imgSource = Name Image original
        w = Width
        h = Height
        pathDestiny = Path where you want put new Image
        imgDestiny = Name Image new
        format = "png" or "jpeg"
        ratio = "yes" if you want maintaing its aspect ratio, otherwise "no" and resize your w and h
        Example:<code>
        Dim pic As ResizePicture
        Dim nomepath As String = File.DirRootExternal
        pic.resizeUrl("http://devil-app.eu/immagini_mie/","test.jpg", 250,150, File.DirRootExternal,"vedi","jpeg","yes")</code>
      Permissions:
      • android.permission.INTERNET

    Code Example:
    Code:
    Sub Globals
        
    'These global variables will be redeclared each time the activity is created.
        'These variables can only be accessed from this module.
        Dim pic As ResizePicture
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
        
    'Do not forget to load the layout file created with the visual designer. For example:
        'Activity.LoadLayout("Layout1")
       
        
    File.Copy(File.DirAssets, "test.jpg",File.DirRootExternal,"test.jpg")
       
        
    Dim nomepath As String = File.DirRootExternal 
     
        
    'This Local Picture
        pic.resize( nomepath, "test.jpg"300400, nomepath, "vedi1","jpeg","yes")
       
        
    'This Remote Picture
        'pic.ResizeUrl("http://devil-app.eu/immagini_mie/","test.jpg", 300,400, File.DirRootExternal,"vedi","jpeg", "yes")

    End Sub
     

    Attached Files:

    Last edited: Mar 22, 2015
  2. NJDude

    NJDude Expert Licensed User

    Just a small grammatical correction, it should be "pathDestination" not destiny ;) but I think it would be better to use "pathLocation".
     
  3. MarcoRome

    MarcoRome Expert Licensed User

    oppss... is really "Destiny" that in evening wrong :D
     
  4. thedesolatesoul

    thedesolatesoul Expert Licensed User

    I prefer destiny.

    Question, does it fully load the image in memory before doing the resize?
     
  5. MarcoRome

    MarcoRome Expert Licensed User

    Yes...but maybe is possible add this:
    Code:
    BitmapFactory.Options options=new BitmapFactory.Options();
    options.inSampleSize = 
    8;
     
  6. bryon

    bryon Member Licensed User

    Hi,

    It seems I can only get this to work if I copy a file from DirAssets. I tried copying files from DirDefaultExternal but get null pointer exception.

    Code:
    Sub ProcessImage(strPath As String, strFile As String)   
        
    Dim TempBmp As Bitmap
        
    Dim strfile2 As String

        
    Log(strPath)
        
    Log(strFile)
        
    Log(File.Exists(strPath,strFile))
       
        
    'File.Copy(File.DirAssets,strFile,strPath,strFile)  <---- Only works if I have the file in DirAssets previously (and uncomment this line).
       
        pic.resize(strPath,strFile,
    300,300,strPath,strFile,"jpeg","yes")
       
    End Sub

    Any idea what could be going on?

    Thanks.
     
  7. MarcoRome

    MarcoRome Expert Licensed User

    Are you sure that you have file in DirDefaultExternal ???
    Because now i try with this code and work without problem.
    Code:
    Sub Activity_Create(FirstTime As Boolean)
        
    'Do not forget to load the layout file created with the visual designer. For example:
        'Activity.LoadLayout("Layout1")
      
        
    'File.Copy(File.DirAssets, "test.jpg",File.DirRootExternal,"test.jpg")
        File.Copy(File.DirRootExternal,"mio_b.jpg"File.DirRootExternal,"mio_b1.jpg")
      
        
    Dim nomepath As String = File.DirRootExternal
        
    'This Local Picture
     
        pic.resize( nomepath, 
    "mio_b1.jpg"300400, nomepath, "vedi1","jpeg","yes")
     

    Attached Files:

  8. bryon

    bryon Member Licensed User

    Yes. I can see the file with a file manager app and also the Log(File.exists) shows true.

    This is running in a service. Do you think that would affect it?

    Thanks.
     
    dar2o3 likes this.
  9. MarcoRome

    MarcoRome Expert Licensed User

    Do you try in activity ?
     
  10. bryon

    bryon Member Licensed User

    I've been trying it.
    Something weird is going on...
    My app downloads an image file to the "images" directory. I can verify it is there with a file manager app and it can be viewed in a webview. BUT, if I try to open it from within the file manager app, it fails.

    Then I explicitly copied a file from another directory to the images directory and it worked. This copied file can also be viewed in the manager app.

    Code:
    resizepic.resize( File.DirDefaultExternal & "/momblog/images","pic1.jpg"300300File.DirDefaultExternal & "/momblog/images""pic1_rs","jpeg","yes")
    It appears the downloaded image is corrupt. But if so, why can I view it in a webview?

    I'll have to go deeper..

    Thanks.
     
  11. mvera

    mvera Active Member Licensed User

    gracias
     
  12. Erel

    Erel Administrator Staff Member Licensed User

    Next time please use the small Like link instead.
     
    MarcoRome likes this.
  13. mvera

    mvera Active Member Licensed User

    Hi.
    I'm having trouble with this library when I take the second photo.




    fotos_camara_picturetaken (B4A line: 87)
    pic.resize( nomepath, "foto.jpg", 300, 400, nomep
    java.lang.OutOfMemoryError
    at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:652)
    at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:391)
    at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:451)
    at com.devil.app.ResizePicture.resize(ResizePicture.java:130)
    at r.ieidesign.fotos._camara_picturetaken(fotos.java:481)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
    at anywheresoftware.b4a.BA$2.run(BA.java:299)
    at android.os.Handler.handleCallback(Handler.java:615)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)


    someone can guide me
    thank you.
     
  14. MarcoRome

    MarcoRome Expert Licensed User

    You have problem with memory ( OutOfMemoryError )
    Can i see your code ??
     
  15. cxdzbl

    cxdzbl Active Member Licensed User

    Is my fault, ok, thank you
     
    Last edited: Jan 13, 2016
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