I have researched this topic on the site, and tried the solutions but nothing that has worked for me so far. I have created a simple program in IntelliJ that compiles just fine, but when I export and make it into a JAR there are errors because of the images. When I take away the images I am able to build and load the JAR file correctly. I keep my image in the SRC file in a sub folder named sample.
public class Main extends Application {
Image image = new Image(String.valueOf(getClass().getResource("/buttona.png")));
Button button1 = new Button("", new ImageView(image));
Button button2 = new Button();
I figured it out and wanted to post the solution for future users. It worked when I used the format shown at the bottom. The key was putting GetClassLoader, and from then finding a path that would work.
np0_up.png is the file
Image Num0 = new Image( getClass().getClassLoader().getResourceAsStream( "sample/np0_up.png"));
Related
I created an add-in to an existing software (Revit) and I want to embed an image (my company's logo) in the add-in's button.
Here is my current code for it:
'Set the large image shown on button
Dim uriImage As New Uri("\\10.8.60.3\Shared\REVIT\FSElogo.png")
Dim largeImage As New BitmapImage(uriImage)
MainButton.LargeImage = largeImage
It works pretty well and the logo is correctly displayed, however it requires the computer to have access to the server located at \\10.8.60.3. When working from home, we do not have access to this server and Revit throws an error when starting because of it.
So I tried adding the FSElogo.png file to my VB.Net project as a Resource and then tried to use My.Resources to access the image, effectively removing the need for an external image to be used.
Well, I can't get it to work.
I tried replacing the code above by
MainButton.LargeImage = CType(My.Resources.ResourceManager.GetObject("FSElogo.png"), Windows.Media.ImageSource)
But it doesn't work. It doesn't throw an error, but no image is displayed on the button.
If I don't cast my Object to an ImageSource I get an implicit conversion from Object to Image error, and I'm not even sure my ResourceManager is even really returning the object FSElogo.png.
What am I doing wrong here?
I am using the VS provided button with the .BackgroundImage property. Notice that the extension of the file is not included in the resource identifier. If this doesn't work, you will have to explain exactly how you added the resource to your project.
MainButton.BackgroundImage = My.Resources.FSElogo
I have an image stored at /assets in my project folder and I am trying to read it using Ti.Filesystem.getFile(). The code prints the blob data in android but it prints undefined in iOS.
Following function is called on Button click event https://pastebin.com/QgqLQPyz
function readImg(e) {
var localPath = '/butterfly.jpg';
var cachedFilename = Ti.Utils.sha1(localPath) + localPath.substr(localPath.lastIndexOf('.'));
console.log("cachedFilename:---"+cachedFilename);
var cachedFile = Ti.Filesystem.getFile(Ti.Filesystem.applicationCacheDirectory, cachedFilename);
if(!cachedFile.exists()){
var blob = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, localPath).read();
console.log("-----------blob in not exists:"+JSON.stringify(blob));
}
}
When the same image path is set in ImageView it gets displayed so the issue is not with path . What am I missing here ? pls help. Thank you.
The best option so you don't have to do anything specific to the images at all (keep in mind, image manipulation is pretty heavy to do on runtime), is to use a module that was made for this purpose, av.imageview. This allows you to configure all kinds of content modes.
An option to get your code to work is to get the blob using the the getAsset method.
var blob = Ti.Filesystem.getAsset('/images/butterfly.jpg');
and then resize where you see fit. But I would advise you, if you do need to do this every time the app runs, then just resize once and store that resized image to be used after that. That way there will only be a single time the image needs resizing.
I am creating automated test cases by using selenium 3 & testng. Everything looks good, except the screenshots that are generated. Here is my piece of code to create screenshots PNG files:
file = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(file, new File(pngfile));
which is pretty standard way to do it, but the quality of the created PNG file is not so good.
As you can see from following PNG file. In the picture, the email value ( "....#yahoo.com"), which should be at the upper-right corner of the web-page and should be as high as the other navigation bar elements on the left side. But in the created PNG file, this item has been squeezed to the lower level, which is not what I am looking for. Any ideas ? Thanks for the help !
Make sure your window is the right size when you're opening the browser. You can do this via visual inspection or using Selenium's getSize method. I assume you're using Java, but here it is in Python as well.
Then, if the window is not of the correct size in order to guarantee that your webpage's CSS doesn't break, use setSize. Here is that method in Python as well.
Afterwards, your screenshot should look like the window does.
Please try this,
public void calltakeScreenShot(String SSName) throws Exception
{
File screen = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
BufferedImage img = ImageIO.read(screen);
File filetest = Paths.get(".").toAbsolutePath().normalize().toFile();
ImageIO.write(img, "png", new File(filetest + "\\Screenshots\\" + SSName + ".png"));
}
Additionally Here you just need to pre-created Screenshots folder in your Project directory. It will store it by getting absolute path of your project. Also you can manage screenshot name by passing argument.
After several day's research, here is my latest summary.
A). If I was executing the scripts, that is not in the "headless" mode. When the selenium test case is being executed, I will see a new browser session is being popped up and get to that URL, click some buttons, etc, ... till the execution is finished. In this execution, the screenshot page will be saved in good quality.
B). For the same selenium test script, if I am including one extra ChromeOptions setting, which is "--headless", I will not see any browser being brought up during the execution. And once execution is finished, I will get the screenshot with such squeezed web elements.
Comments ?
In my application i am binding several properties to a custom user control, and everything works fine, except the images are not showing. For binding i have used the following codes:
Categories.Add(new Models.Category { Name = "Pizza", Count= 4, ImageUri = new Uri("Images/pizza.png", UriKind.Relative) });
I have also tried with different urikinds but the images are never showing.
what could go wrong? The images are in my solutions Images folder.
Use the ms-appx URI scheme:
ImageUri = new Uri("ms-appx:///Images/pizza.png");
Take care to really write ///.
Also make sure that the Build Action of the image file is set to Content, as pointed out in the other answer. Setting Copy to Output Directory does however not seem to be necessary.
Be sure you set the properties of the image so that it is available during runtime. Sometimes if employing Design Time data in Blend, you will see the images in Design Time, but then nothing during run time. The reason is that the images were never deployed with the rest of the solution. Be sure the Build Action on each image is set to Content and I usually set the Copy to Output Directory to Copy if Newer.
I want to setup IntelliJ IDEA to compile Processing sketches. So far I've been following the instructions found here:
http://www.slideshare.net/eskimoblood/processing-in-intellij
These instructions work fine for code completion and basic "drawing". But I run into problems once I want to access files – i.e. an image - inside the data folder which is created on slide 19. First the code of my Processing class:
import processing.core.PApplet;
import processing.core.PImage;
public class IntellijTest extends PApplet
{
private PImage image;
#Override
public void setup() {
size(400, 400);
println(sketchPath);
// load image
image = loadImage("test.png");
}
#Override
public void draw() {
background(0);
noStroke();
fill(200);
rect(100, 100, 200, 200);
// draw image
image(image, 110, 100);
}
}
This leads to the following error:
/Applications/IntelliJ IDEA 12.app/bin
The file "test.png" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.
Exception in thread "Animation Thread" java.lang.NullPointerException
at processing.core.PGraphics.image(PGraphics.java:3572)
at processing.core.PApplet.image(PApplet.java:12604)
at IntellijTest.draw(IntellijTest.java:28)
at processing.core.PApplet.handleDraw(PApplet.java:2306)
at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:243)
at processing.core.PApplet.run(PApplet.java:2177)
at java.lang.Thread.run(Thread.java:744)
As you can see the sketchPath is set to "/Applications/IntelliJ IDEA 12.app/bin". So the running sketch (Applet) does not find the image. IntelliJ does even warn me about it, but I still haven't figured out how to add the image to the sketch or better how to set the correct sketchPath value so that the sketch finds all files inside the data folder at runtime.
I'ld really appreciate any hints or insights on how to accomplish this.
I just had the same problem. I solved it by marking the data directory as Source Root
You can include files into your target directory without having to include it in your source folder. To accomplish you need to "mark it" the auxiliary folder as a source folder.
I keep my source files in /src/main/java and my resources in /src/main/resources where resources contains all my configuration properties and other things that don't belong in the source code. You can right click on the folder in the project explorer and "Mark it" as source. It should appear at the root of your target/project/.
Also keep in mind if you're running a Java Application (not Applet), Java will uses the system environment classpath to resolve relative paths. So as you start calling files in your program, Java will look in the folders listed in the classpath to resolve file locations as well as look in the root of your target project.