B4A Library Library Resize Image 1.1

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:
B4X:
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", 300, 400, 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
 

Attachments

  • Library_ResizePicture1.0.zip
    5.1 KB · Views: 477
  • Library_ResizePicture1.1.zip
    6.4 KB · Views: 839
Last edited:

MarcoRome

Expert
Licensed User
Longtime User
I prefer destiny.

Question, does it fully load the image in memory before doing the resize?
Yes...but maybe is possible add this:
B4X:
BitmapFactory.Options options=new BitmapFactory.Options();
options.inSampleSize = 8;
 

bryon

Member
Licensed User
Longtime 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.

B4X:
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.
 

MarcoRome

Expert
Licensed User
Longtime 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.

B4X:
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.

Are you sure that you have file in DirDefaultExternal ???
Because now i try with this code and work without problem.
B4X:
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", 300, 400, nomepath, "vedi1","jpeg","yes")
 

Attachments

  • picdemo.zip
    8.4 KB · Views: 354

bryon

Member
Licensed User
Longtime 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.
 

bryon

Member
Licensed User
Longtime 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.

B4X:
resizepic.resize( File.DirDefaultExternal & "/momblog/images","pic1.jpg", 300, 300, File.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.
 

mvera

Active Member
Licensed User
Longtime 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.
 

MarcoRome

Expert
Licensed User
Longtime User
You have problem with memory ( OutOfMemoryError )
Can i see your code ??
 

cxdzbl

Active Member
Licensed User
Are you sure that you have file in DirDefaultExternal ???
Because now i try with this code and work without problem.
B4X:
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", 300, 400, nomepath, "vedi1","jpeg","yes")
Is my fault, ok, thank you
 
Last edited:

JohnC

Expert
Licensed User
Longtime User
I have a quick question...

One of the parameters is "Keep Ratio".

So, if I enable this feature, then which of the output W or H parameters is ignored so it can keep the aspect ratio?
 

MarcoRome

Expert
Licensed User
Longtime User
I have a quick question...

One of the parameters is "Keep Ratio".

So, if I enable this feature, then which of the output W or H parameters is ignored so it can keep the aspect ratio?
As Erel suggested, it ISNT necessary to use this library
 

MitchBu

Well-Known Member
Licensed User
Longtime User
I should have read this thread through. I wasted all afternoon yesterday on the library, which simply does not work with File.DirInternal. Seems it is not able to create the output file. Perhaps changes in system. IMHO this entire thread should be removed.

Here is a link to Erel's tutorial for Bitmap.Resize and LoadBitMapResize:
https://www.b4x.com/android/forum/threads/82693/#content

While I am at it, the Drawing(Core) page needs to be updated with these new methods. When I looked at it first I could not find any resize, and landed here, when I could have spared myself some grief.

https://www.b4x.com/android/help/drawing.html
 

MarcoRome

Expert
Licensed User
Longtime User
I should have read this thread through. I wasted all afternoon yesterday on the library, which simply does not work with File.DirInternal. Seems it is not able to create the output file. Perhaps changes in system. IMHO this entire thread should be removed.

Here is a link to Erel's tutorial for Bitmap.Resize and LoadBitMapResize:
https://www.b4x.com/android/forum/threads/82693/#content

While I am at it, the Drawing(Core) page needs to be updated with these new methods. When I looked at it first I could not find any resize, and landed here, when I could have spared myself some grief.

https://www.b4x.com/android/help/drawing.html
Hi. Work also dirinternal ( again use this library in few project ).
But as suggested by Erel it is better to use Bitmap.Resize.
 
Last edited:
Top