Dec 15, 2022 Replies: 13 Introduction: I don't know if there is any library exist to resize image in B4J non-UI app. I thought such library will be useful to process images for web server in building REST API for e-commerce or e-learning web apps. I found an example on web and chose the third method, from an old project call ImgScalr. I done some experiments and manage to get it work in B4J using Inline Java. Then I tried to compile the project as a library. boop! Done. It is so easy and I have my .jar and .xml files ready to use. Supported file types: JPG JPEG PNG BMP WBMP Note: GIF is not supported Additional Jar: imgscalr-lib-4.2.jar ImageScaler Author: Aeric Poon Version: 1.00 ImageScaler Functions: Initialize As String IsInitialized As Boolean Resizeimage (InputDir As String, OutputDir As String, Filename As String, Width As Int, Height As Int, Mode As String) As String Mode: AUTOMATIC, FIT_EXACT, FIT_TO_HEIGHT and FIT_TO_WIDTH Reference: https://www.baeldung.com/java-resize-image Example: Private img As ImageScaler img.Initialize img.ResizeImage(File.DirApp, File.DirApp, "sonic.jpg", 200, 200, "AUTOMATIC") Attachments ImageScaler.jar ImageScaler.jar 2.8 KB · Views: 583 ImageScaler.xml ImageScaler.xml 1.8 KB · Views: 607 imgscalr-lib-4.2.jar imgscalr-lib-4.2.jar 27.2 KB · Views: 632 Source.zip Source.zip 1.9 KB · Views: 613 Last edited: Feb 24, 2023 Click to expand...
Introduction: I don't know if there is any library exist to resize image in B4J non-UI app. I thought such library will be useful to process images for web server in building REST API for e-commerce or e-learning web apps. I found an example on web and chose the third method, from an old project call ImgScalr. I done some experiments and manage to get it work in B4J using Inline Java. Then I tried to compile the project as a library. boop! Done. It is so easy and I have my .jar and .xml files ready to use. Supported file types: JPG JPEG PNG BMP WBMP Note: GIF is not supported Additional Jar: imgscalr-lib-4.2.jar ImageScaler Author: Aeric Poon Version: 1.00 ImageScaler Functions: Initialize As String IsInitialized As Boolean Resizeimage (InputDir As String, OutputDir As String, Filename As String, Width As Int, Height As Int, Mode As String) As String Mode: AUTOMATIC, FIT_EXACT, FIT_TO_HEIGHT and FIT_TO_WIDTH Reference: https://www.baeldung.com/java-resize-image Example: Private img As ImageScaler img.Initialize img.ResizeImage(File.DirApp, File.DirApp, "sonic.jpg", 200, 200, "AUTOMATIC")
Olaan Expert Licensed User Longtime User Feb 9, 2025 #4 aeric said: Source code attached in post #1 Click to expand... I think the code has something wroing. It has no reference from file.DirAsset, has it? Or you need to test someone have tried to test the app.
aeric said: Source code attached in post #1 Click to expand... I think the code has something wroing. It has no reference from file.DirAsset, has it? Or you need to test someone have tried to test the app.
aeric Expert Licensed User Longtime User Feb 9, 2025 #5 Theera said: I think the code has something wroing. It has no reference from file.DirAsset, has it? Or you need to test someone have tried to test the app. Click to expand... There is nothing wrong. Just use your own image to test. You can change the path to your need. Don't take it as it is.
Theera said: I think the code has something wroing. It has no reference from file.DirAsset, has it? Or you need to test someone have tried to test the app. Click to expand... There is nothing wrong. Just use your own image to test. You can change the path to your need. Don't take it as it is.
Olaan Expert Licensed User Longtime User Feb 9, 2025 #6 aeric said: There is nothing wrong. Just use your own image to test. You can change the path to your need. Don't take it as it is. Click to expand... I've test, it has error 'file not found', although I have input my image in file tabs, the log shows 'never used the file' I think that it should have the line File.copy(File.DirAsset, "xx.png", File.DirApp, "xx.png") before.
aeric said: There is nothing wrong. Just use your own image to test. You can change the path to your need. Don't take it as it is. Click to expand... I've test, it has error 'file not found', although I have input my image in file tabs, the log shows 'never used the file' I think that it should have the line File.copy(File.DirAsset, "xx.png", File.DirApp, "xx.png") before.
aeric Expert Licensed User Longtime User Feb 9, 2025 #7 Theera said: I've test, it has error 'file not found', although I have input my image in file tabs, the log shows 'never used the file' I think that it should have the line File.copy(File.DirAsset, "xx.png", File.DirApp, "xx.png") before. Click to expand... DirApp mean Objects folder. Is the file exist there?
Theera said: I've test, it has error 'file not found', although I have input my image in file tabs, the log shows 'never used the file' I think that it should have the line File.copy(File.DirAsset, "xx.png", File.DirApp, "xx.png") before. Click to expand... DirApp mean Objects folder. Is the file exist there?
Olaan Expert Licensed User Longtime User Feb 9, 2025 #8 Your sourcecode has no reference the file from file.DirAsset. I don't know how to test app.
Olaan Expert Licensed User Longtime User Feb 9, 2025 #9 I don't understand about why do you create non-ui app, how to get the lastest image to use?
aeric Expert Licensed User Longtime User Feb 9, 2025 #10 Theera said: Your sourcecode has no reference the file from file.DirAsset. I don't know how to test app. Click to expand... Because it doesn't need to rely on file in File.DirAssets. Your problem is you don't understand how to work with B4J, B4A or B4i on the file system. I already provided an answer that you need to put the file in Objects folder.
Theera said: Your sourcecode has no reference the file from file.DirAsset. I don't know how to test app. Click to expand... Because it doesn't need to rely on file in File.DirAssets. Your problem is you don't understand how to work with B4J, B4A or B4i on the file system. I already provided an answer that you need to put the file in Objects folder.
aeric Expert Licensed User Longtime User Feb 9, 2025 #11 Theera said: I don't understand about why do you create non-ui app, how to get the lastest image to use? Click to expand... The library can work not only on B4J non-UI app, you can make it work on B4J UI app and B4A by changing the path. Reason I used non-UI app is for web server which is lack of UI support, in B4J case JavaFX or XUI.
Theera said: I don't understand about why do you create non-ui app, how to get the lastest image to use? Click to expand... The library can work not only on B4J non-UI app, you can make it work on B4J UI app and B4A by changing the path. Reason I used non-UI app is for web server which is lack of UI support, in B4J case JavaFX or XUI.
Olaan Expert Licensed User Longtime User Feb 9, 2025 #12 Your problem is you don't understand how to work with B4J, B4A or B4i on the file system. Click to expand... It means that copying the image file into objects folder directly,doesn't it? Last edited: Feb 9, 2025
Your problem is you don't understand how to work with B4J, B4A or B4i on the file system. Click to expand... It means that copying the image file into objects folder directly,doesn't it?
aeric Expert Licensed User Longtime User Feb 9, 2025 #13 Theera said: It means that copying the image file into file folder directly,doesn't it? Click to expand... No I repeat second time. Objects folder.
Theera said: It means that copying the image file into file folder directly,doesn't it? Click to expand... No I repeat second time. Objects folder.
aeric Expert Licensed User Longtime User Feb 9, 2025 #14 Theera said: I think that it should have the line File.copy(File.DirAsset, "xx.png", File.DirApp, "xx.png") before. Click to expand... You can put the file in Files folder and load to the tab and use the above code to copy to File.DirApp which means it will copied to Objects folder. This is extra steps which is not needed. I want to clarify, this class initially is intended to use in server. In real world use case, user will upload images to server and saved into a static files folder (www) inside Objects folder. So there is no point to put images into assets folder. For example purpose, you can use your own images for testing. Just drop it to Objects folder.
Theera said: I think that it should have the line File.copy(File.DirAsset, "xx.png", File.DirApp, "xx.png") before. Click to expand... You can put the file in Files folder and load to the tab and use the above code to copy to File.DirApp which means it will copied to Objects folder. This is extra steps which is not needed. I want to clarify, this class initially is intended to use in server. In real world use case, user will upload images to server and saved into a static files folder (www) inside Objects folder. So there is no point to put images into assets folder. For example purpose, you can use your own images for testing. Just drop it to Objects folder.