I'm trying to pull the path of a screen image I'm looking at on the android phone of the app im testing. The app shows various pictures. I want to pull the path of the picture to pull the picture name, but have no clue how to start. Any guidance?
edit:
I'm trying to find out if I could pull the path from the app code to see which image the user is viewing. for example. if im looking at an image, I want to know whats the path of the image (path should be coming from someone's harddrive)
there's not necessarily a path for an image. it's better to say the source of the image, be it a file, an HTTP stream, or otherwise. and unfortunately, that info is lost once it's set into an ImageView.
to set the image bits into an ImageView, you construct a Bitmap, usually using one of the decode*() methods in BitmapFactory. that is what determines the source of the image. in your unit test framework, you can get a handle to the ImageView by getting the Activity and calling findViewById(), but that's not going to help you.
there may be other places for you to hook into the code to determine that sources for the image data, but i can't say without knowing your application source code.
you could ask your developers to make the source available in the ImageView's tag (see setTag() / getTag()). that way you could pull it out in your unit tests. of course, you'll have to have an understanding with them as to what the source will be (a URL, a database URI, a file path, ?).
Related
I use Rich text Editor for uploading images & I create 1 data source for uploading image. When I upload image it is not shown (broken image logo), while I am not publish this image.
What is the problem?
The image is not shown because it cannot be severed for some reason. There could be any number of reasons for this. Here is how I would trouble shoot the issue:
upload an image via the RTE
Right click on the image, inspect element, look at the path to the image
it should say PROTOCOL://SERVER:PORT/static-assets/etc/etc/etc
If the URI doesn't start with static-assets then Crafter's download servlet cannot serve it. You need to fix the path in your datasource.
If the path does start with static-assets then check and see if the image is in your repository at that path specified. You probably won't find it there. If that's the case check your tomcat logs for an error. If the error doesn't help you, post it here and we will go from there.
I am a beginner Java developer and I have created an application in Java (Netbeans).
I have used buttons icons, backgrouds for jframes etc. When I built the project, they can easily accessible using WinRAR. Anyone can extract my jar file and see all the images that I have used in my program. Even the images used in jpanel that is not accessible without password.
How can I hide or protect these images?
I have created a .exe file also using Launch4j but still facing same problem. When I right click on the .exe file, its easy to extract my whole program.
To be honest, if someone wants your picture, they are going to be able to get it. One can simply do a print screen. However you can still do somethings.
Remove the extensions for the picture files and give them crazy names - this will make it harder for people to find your pictures
Encript the files then have the application decript them when loading - I don't know how to do this but shouldn't be too hard to find, for instance you could save the pictures as a byte stream with some alterations then reload it.
Save the picture in some archive which only your application knows how to read.
But anyway even with all these things, I still know how one could get a handle to an open JFrame, look through the components, and then could get your picture. IMHO trying to prevent people for getting your pictures is not worth doing.
I am loading an image from an URL like this:
new ImageIcon(new URL(url))
The url is something along the lines of http://example.com/image.png, so an image on the internet.
This works just fine, however I've been getting a few reports of users of my program that they are getting strange images instead of the regular ones when using the program on a retina display on Java 8u20 (and maybe later).
I determined that the strange images they are getting is an image that the CDN the images are loaded from automatically redirects to if the image wasn't found. After some research, I found that newer versions of Java apparently automatically add #2x into the url when using the Toolkit.getImage(URL url) method (https://bugs.openjdk.java.net/browse/JDK-8011059), which is used by new ImageIcon(URL url).
The problem of course is that the CDN actually returns a valid image if the image isn't found, so Java probably thinks it actually found a higher resolution image to use on the retina display. Other images in my program that also use ImageIcon in the same way, but are loaded from another source, seem to work just fine.
The question is now, what would be the best way to resolve this? I don't have access to the CDN, so I have to prevent Java from trying to load the second URL somehow (if that is actually the problem, but it certainly seems that way). Unfortunately I don't have a computer to test this on, so it's a bit hard to tell which solution will work.
So I have a java application that displays a jasper report. There is an image I placed in the report using the iReport plugin for netbeans. Everything displays fine on my current machine but when I try to run the compiled jar on a different machine, the report won't load.
From looking at the windows console, I think it's because the path to the image is absolute, i.e. referencing a specific folder on the hard drive of the development machine. I need to make it relative to the jar file. I've placed the image into the package and have confirmed it's inside the compiled jar. But when I change the "image expression" value in iReport to "/reports/Logo.jpg" (where /reports is the package) and run the app I get
EXCEPTION: Byte data not found at : /reports/Logo.jpgnet.sf.jasperreports.engine.JRException: Byte data not found at : reports/Logo.jpg
Any ideas what to do? I am very stuck and would appreciate any help!
UPDATE: Got it. Had to create a parameter in the report and called the parameter from the image expression. Then I created a HashMap and InputStream in the Java code and placed the input stream into the hash map! So much code for so simple a thing!
Java code:
//to get images to display in report, pass their relative path as input stream and add to HashMap
//there must be one stream and one HashMap per image
InputStream imgInputStream = this.getClass().getResourceAsStream("/reports/omacLogo.jpg");
InputStream imgInputStream2 = this.getClass().getResourceAsStream("/reports/omacLogo.jpg");
parameters.put("omacLogo", imgInputStream);
parameters2.put("omacLogo", imgInputStream2);
InputStream jasper1 = this.getClass().getResourceAsStream("/reports/OmacYTDReportFinalpg1.jasper");
InputStream jasper2 = this.getClass().getResourceAsStream("/reports/OmacYTDReportFinalpg2.jasper");
JasperPrint jp1 = JasperFillManager.fillReport(jasper1, parameters,new JRBeanCollectionDataSource(ie.orderofmalta.BeanFactory.getCalcs()));
JasperPrint jp2 = JasperFillManager.fillReport(jasper2, parameters2, new JRBeanCollectionDataSource(ie.orderofmalta.BeanFactory.getCalcs()));
Hope this helps someone else! Be aware you have to create separate hash maps and input streams for each image you want to place, even if it's the same image.
I've personally had not tried this way with a jar, but i hope it helps. As you've stated the problem comes from the file path. On the iReport tool you can use relative paths and it works on the preview, but when the report generation is integrated within an application, it can only work with absolute paths.
The way i've dealt with this drawback was by getting the absolute path of the image inside the java application, and passing it as a parameter to the report. Example:
String image = FacesContext.getCurrentInstance().getExternalContext().getRealPath("/Cards_Template/front.jpg");
NOTE: I've built a JSF app, that's why i'm getting the path from it's context. If you don't, Java's IO or NIO API does have some methods to do the same. Basically, i get an absolute path from a relative path.
I am attempting to make a certain image a background image for an application. I know the syntax (android:src="*int*"), at least I think that's it. But I don't know what kind of a source I could use. A directory pointing to a file? A URL?
Why not add/save/move the image to your res> drawable folder and have :
android:src ="#drawable/image"