I am fairly new to java. I have written an application that basically has a 50x50 grid of buttons, with each button opening a specific image related to that button. The images are stored on my file system.
The app works perfectly in Netbeans, each button opens up the correct image.
I would now like to export the app to be able to share it with some people that are interested - however I am not sure what is the best way to do this. I have been googling this for days but haven’t found anything that really answers my question.
What I would prefer is this: The user installs/unzips/whatever the app, and as a result is left with a folder with all the image files (quite a lot of them and around 1Gb in size) and a runnable file, preferrably an .exe to run the program.
What would be the best way to achieve something like this?
At first I was thinking about including all the image files in a runnable JAR. The problem with this approach is that I would have to rewrite my code, as right now my code uses java.io.File to fetch the images and to my knowledge this doesn’t work inside a JAR. Also I would much prefer an .exe instead of a JAR.
Any help will be greatly appreciated!
as right now my code uses java.io.File to fetch the images
Are you saying that you use java.io.File to get a listing of available images or that you're using it to read an image?
If you need a list of images or resources inside a jar take a look at "How to list the files inside a JAR file?"
To read an image from inside a jar using JavaFX, you just need to get the URL to the image:
import javafx.scene.image.Image;
URL url = getClass().getResource("/path/inside/jar/myimage.png");
Image image = new Image(url.toExternalForm(), true);
As to the best way to deploy that app ... I would say that a 1GB app is a beast. Could you host the images on a web server and have the app lazily fetch the images as they need to be displayed?
Related
I can't find how to load my own icons in Flet.
I'm testing Flet with the intention of making a desktop app (pure desktop, not Internet needed), but I'm not able to use my own icons to begin with. I can only use the ones that come inside ft.icons, but I'd rather use my own by loading them from a folder similar to /assets/icons. Can I do that? How?
Thanks.
Currently, I don't see a way of doing this; however, you could use the Image class instead.
I would suggest you create an assets folder under your main project folder.
Let's assume you have the following folder structure on your project:
/assets
/icons/my-icon.png
main.py
When you are running your app, you should provide that folder to the initializer in the following way:
flet.app(target=YourApp(), assets_dir="assets")
Then you can access your images there directly and create an Image instance in the following way:
test_image = flet.Image(src="icons/my-icon.png", width=32, height=32, tooltip="Image Tooltip")
You can nest these Image controls inside of anything you want, so you have a lot of flexibility.
The only downside of doing it this way is if you are using light/dark themes on your app. Compared to the Icon class, you will have to specify the light/dark theme versions yourself and update them manually when you are switching your theme.
Here is the official documentation
From Symfony 5, I installed and configured the CKEditor buundle and attach it to the Elfinder bundle.
All works perfectly. Now, for increase the users experiences, I would like convert automatically any png file updated via elfinder to jpg file (for save disk space usage ;) )
Despite my researches, I can't find if there is a CKEditor and/or Elfinder way for upload image.
Nothing in the documentation. I also look the result of the php bin/console config:dump-reference fm_elfinder command, but I don't find anything about a conversion...
Does that mean there isn't a quick/provided way for do what I'm looking for ?
Thanks for any help :)
Are you sure that it will increase the users experiences to convert their png to a jpg image? I don't think so, you will loose a lot of functionalities of png (transparency, color protection, etc.). Do not forget that png image can be compressed too!
If you are sure that, in your case, it will increase the users experience, this bundle does natively not do it. You'll have to code. I saw two solutions:
Solution1: FMElFinderBundle comes with a plugin to resize image. You could perhaps have a look on it to create a new specification which will transform png into jpeg instead of resize it.
Solution2: FMElFinderBundle use the FileSystem Symfony component to store image. This bundle allows developers to change this component (If you want to replace it by an Amazon service as example). You could create your own component by overriding the Symfony filesystem. Just replace the dumpfile or the copy methods. If file is a png, you call the gd2 library to convert it.
I am working on a Gradle JavaFX project in IntelliJ. My question is essentially "How do I get a background-image URL working for JavaFX in CSS?" for which the answer would be:
.button{
-fx-background-image: url("/image/CloseButtonBlack.png");
}
except that this doesn't work for me. After much experimentation, I have discovered that if I move the file up one level so it lies directly in the resources folder, everything works. Because of this, I believe that the reason the file doesn't display when it lies within the image folder is that the image folder is not marked as a resource folder. If I were not using Gradle, I believe I could fix this just by using IntelliJ's Project Structure -> Modules menu. Since I am using Gradle though, I am thinking that the correct way to fix this would be to write some code in build.gradle so that Gradle knows the image folder is a resource folder. If I am right, what code is it that I need to write to get my background image to display while it lies in the image folder?
javafx set application ico
when i create java project , add jfxrt.jar
it's right
new Image(getClass().getResourceAsStream("../images/customLogo.png"))
but this in javafx project
it's wrong.
how can i get relative path do this in javafx project.
I think that you should take a look on the Image API and this another link where how to put the icon is answered.
If you were generating a jar, you can use
new Image("/path/to/image")
The path to the image starting with "/", will be an absolute path inside the jar. I strongly recommends go to the Image API to check all the options, is really well documented.
Hope it helps
So what is the exception? Where did you create the project (which IDE). As a general rule never use ..-paths when doing look ups although the might work on the filesystem they e.g. break inside jar-files IIRC.
I've a flex application which has actionscript file, images. When i run this in adobe flash builder, everything works. When i export it as a release build and run in other file, swf does not show images and interactivity of flex components is also lost.
Is there a specific way to embed images?
Here is image code,
I don't see your code, but I've had similar issues before. The trick is to reference the image starting with a forward slash '/' in the path. For example, if the image is located at 'img/test.png' then use '/img/test.png' as the embed source path. You should also check to make sure the image is included in your build path.