I'm in the process of writing a read/write library for Windows PE files using Java (and eventually hope to release it as OpenSource). For now though this is for cross platform compatibility and will allow me to modify strings/version info/icons/resources etc from an Ant build system or command line/terminal etc.
The problem I have reached is that I can now embed icons in the .rsrc section from a source BMP file and have it display them but unfortunately (Even though the data is correct) the icon comes out within Windows Explorer (and CFF Explorer/ Visual Studio etc) as incorrect. It has a sort of pattern across the raster data as if the image something has be Xor'd or digitally signed.
Any ideas what i'm doing wrong when adding this data?
On a side note I'm also a bit confused as to why I need to modify the height part of the BMP header so that its marked as 2x its real size.
Thanks In Advance.
- Tim.
Related
I have created a GUI using java Swing which displays some images. I have been testing it and have managed to create some labels which I have filled with JPEG images as a test.
Now, I face the problem that I cannot display the actual files i need to display because they are .nd2 files (from a Nikon microscope). I have been looking at how to use the Bio-formats and/or IJ packages to do so...but I don't know where to start.
Can anyone help? I am using the Eclipse IDE for Java
About the format
From https://www.file-extensions.org/
... The ND2 format uses JPEG-2000 compression, and also can be
uncompressed or Zip-compressed ...
As mentioned in read jpeg2000 files in java
JPEG 2000 seems to be not included inside standard Java SDK.
Potential solutions
1. Use Open JPEG + existing JNI wrapper
I would try out https://github.com/uclouvain/openjpeg and search for some java wrappers to use openjpeg (e.g. look at https://github.com/barmintor/openjpeg for an JNI approach for maven).
2. Use Open JPEG + Write own JNI wrapper
Another approach would be to look at
https://github.com/ThalesGroup/JP2ForAndroid/blob/master/library/src/main/java/com/gemalto/jp2/JP2Decoder.java , inspect involved classes etc. and write an own JNI wrapper
The mentioned github reposoitory code writes to android bitmap, so not directly usable for your Swing project, but it shows you the way to decode JPEG2000 format by native calls to OpenJPEG library
How to convert a byte[] to a BufferedImage in Java? describes conversion from byte array to a buffered image - so these information should help you to read the image data into a buffered image (so usable in Swing).
My app is saving images into a folder. Simultaneously another piece of software watches over this folder and prints pasted images.
Problem I've encountered is that printing app can send on printer half rendered image or doesn't react to saved images at all.
I'm using javax.imageio.ImageIO.write(RenderedImage im, String formatName, File output) to save BufferedImage into png format.
If locking required please provide a code example with explicit locks. If not explain why.
I've tested on Windows, JRE 1.8
Basically, you should write the image to a temporary file and then rename it to the final file name. this way the file is completely written before the other app becomes aware of it.
You probably want to implement some kind of locking mechanism that files are only read when they are completely written, or not at all.
I was wondering if it is possible to load a huge JPEG (see my previous question there) and save it / use it in a quickly-loadable format, without loading its fully decoded contents into memory.
The main idea is to have a file format (or a function I'm not aware of which would do that natively in Java) allowing to load dynamically a given area of the image, without loading 800MB of data.
I'm actually using a tiling algorithm to render the image, but it needs to load the full image (thanks to mKorbel and Gerard Le Blanc), but this "preloading" step remains quite long.
I don't figure out how to do that (and first of all, is it possible ?), since Google did not help me a lot (maybe bad-english searching ?)
I found what I needed there :
very large image manipulation and tiling
The Java JAI lib has a lot of features to handle these kind of problems, and is supported by Oracle, which means it is (theoretically) stable and sustainable.
Thanks to #BryanD !
I have a grayscale pdf with a few images and Text to print inside of Java. The usual approach via rendering to a graphics object and sending to a printer per java.awt.print or org.eclipse.swt.print results either in a blurred output or takes several minutes to print (The rendering process is fast though).
I have already tried many opensource renderer (PDFBox, jpod, PDF Renderer) or commercial products (crionics JPDF, Gnostice PDFOne,...).
It seems all these libraries are using in some way the java.awt.print API and render the pdf File to the internal graphics.
I'm looking for a more direct approach, like converting the pdf to postscript (or another, for the printer more readable format) and then printing it directly, without the need of rendering it first).
It should work for most printers and on Win/MacOsX/Linux likewise :)
The trick I am using in one of my applications, is to execute an OS command with Runtime.exec(). It works fine on Mac OS X and Linux with the command lp . On Windows the command would be AcroRd32.exe /t , but the acrobat reader must be installed and the .exe file must be located somehow (by putting the directory in the PATH for instance).
A PDF I generate with jasper reports renders Ok in my MAC but some labels show wrong on Linux. For example, I have a static label that doesn't show completely on linux (only a part of the whole word) but yes on Mac. Can the OS be somehow related? What is the usual source of this kind of problems?
Missing fonts on your linux machine may cause such problems. I had the same when creating pdfs with iText.
Always embed fonts in generated PDFs! It saves you alot of hassles...
And notify the following slight difference: If you create a PDF with Arial as font it shows good in Windows, and will very likely use Helvetica on Linux (which is nearly the same font), but since it has some other metric properties your bounding boxes will not fit.
Again: Always embed fonts in generated PDFs!
If you have time you can look at Docmosis, it generates PDFs with the fonts embedded, so cross-platform rendering isn't an issue. Beware though if you cross-platform generate doc or odf files, then the fonts will be potentially different showing up in pagination or layout changes. Like has been said above, you need to take care that the destination will have the fonts to display those that were used to generate the document (or embed the fonts if possible).
The closes fotn to the PDF Helvetica (SansSerif) is MS Arial.ttf. The problem is that it is not available on the Linux machine by default. Copy it to the /usr/share/fonts (and update fonts.dir) or put it to your Linux JRE installation to fonts/ directory (and update fonts.dir). If you do not want to use MS Arial, try GNU FreeFont http://ftp.gnu.org/gnu/freefont/
You can embed the fonts in the PDF as Daniel has adviced, but it makes PDF larger.