Scaling images/icons in Java - java

A project I am working on needs to be resized when the monitor resolution changes. Due to legacy code and other issues, we do it by using a custom library which scales all the components to the appropriate sizes when the resolution changes.
However, when we scale some of the images/icons used in the project, they become blurry/fuzzy/aliased. Mostly because they are all raster gifs.
One solution we thought might work to mitigate this issue is to either use Vector images and convert them into raster images on the fly (and cache them for performance improvements).
What do you all think? Would this be a good way to go? Or are there better alternatives to my chosen method?
If this is a better way, then can someone give pointers to how to go about the svg conversion to say jpg or png(preferably). Available (and commercially usable) libraries?
Thanks

The algo's in java are pretty good. The fundamental problem sounds as if your original images/icons are already too small so scaling them up leaves you with artefacts. A real simple approach is to have the images sent along with the app to be at the larger size and only scale down. I would say a policy on images sizes (pixels height and width) is necessary as you seem to indicate that only some have problems.
Of course if you can go for vector graphics, you can scale infinitely and this may be a better long term investments depending upon your application and the likely hood of needing to support large output formats (not just screens but printing). It may well be fairly complex to approach things this way. (More information would be needed to help you further with the points in this para.)

Batik can convert svgs into pngs or jpegs

The icons in the Metal (cross-platform) PL&F are drawn into a buffered image, in order to blend in with whatever machine it happens to find itself running on. It's a fast technique, doesn't add dependencies and there's no need to learn any extra APIs (or languages!). See src.zip in your Sun JDK.

Related

Searching for Java library to build an app that interacts with data

I have a project where I should analyse data via cluster analysis. Basically the data should be visualised like this picture shows
Each dataset - for example let it be people - is one horizontal row, where vertical lines showing the attributes like sex, age, and so on.
Now if this data could be shown I also want to move the rows horizontal and also vertical a) via code and b) via drag & drop.
Do anybody know a good library for that?
Important
Target is desktop application
Expected datasets around 500
Attributes for each data set around 60
There is an app in Java/SWT already, so solutions in this direction would be preferred
The OS is Win7 so C# or similar would be a stopgap
I really like d3.js, and would prefer a similar lock & feel (but in 3D)
If somebody has recommendations for a library which helps to analyze the data, please step forward too!
Check What is the best open-source java charting library? and Libraries for pretty charts in SWT? for more info.
I did used JFreeChart with SWT (2 years ago). The code is quite horrible (you have to write tons of code), but it works and is directly renderable with SWT components (no need of SWT_AWT bridge).
EDIT
When I thought about it again, I realized, that you can use the JavaScript library through Browser widget. It's quite heavyweight solution, but it might work..
You can do this in d3 but it is a very involved process in which you need to deal with the ismoetric perspective and the rest. It shouldn't be terribly complicated but it will not be an out-of-the-box solution.

Hiding ImageJ interface elements

I'm working on a project involving enlisting a large number of
relatively unskilled workers to do repetitive image analysis using
ImageJ. I've written a set of macros which walk them through the
analysis process, but in order to increase throughput and reduce
errors, I'd like to figure out how to hide as much of the gui/menu
interface as possible.
An optimal solution would show just the image in question and a set of
icons to select the correct macro. To further complicate things, I'm
planning on delivering the applet and image to be analyzed through a
website (though my understanding is that this shouldn't change too
much).
I've searched a fair bit and can't seem to find an example of how to
do this interface simplification. If anyone can point me in the right
direction I'd be quite grateful. I'm open to any suggestion that works, though since my Java is a bit rusty, a macro/script/configuration solution might be easier.
I solved my problem with the excellent Action Bar Plugin:
http://imagejdocu.tudor.lu/doku.php?id=plugin:utilities:action_bar:start

Problem with FOP Image scaling in Java

Okay, so here's my problem:
We use FOP for creating "pretty" report output. We use the pdf option if the user wants a file, AWT for previewing, and the -print option for printing them. We are using FOP 0.25.x, which I fully recognize is not the newest version, but upgrading to 0.95 appears to be a non-trivial task that I don't necessarily want to undertake.
Anyway, it was noticed by one of our users that when printing ID cards (generated via FOP -print option) to the id card printer, the images on the cards (pictures of the employees) had some corruption in them...sort of like like green and reds dots and lines. We also discovered that if we sent the exact same print request to one of our HP color laserjets, it printed fine. To add to the strangeness, if we use FOP to create a PDF of the ID card and then print it via acrobat reader on the card printer, it prints fine.
I eventually discovered that it had something to do with the scaling of the images...we were scaling 600px high images down to something like 120px. If I presized the images down, even just halfing them, the corruption went down noticeably. Similarly, when I upsized the images, the corruption went up.
So my question: anybody have ANY idea what is going on here? Or has ever run into such a thing?
Since I don't know why this is happening, I don't know how to fix the root cause, but I've been working through some various workarounds:
1) Use FOP to create a pdf of the image and then print that via Java. This seems like an obvious answer, but some Googling around showed that printing a PDF via Java is not trivial. I've seen the PDF Renderer project on java.net, but seems pretty bulky for a single very specific application.
2) Try to resize the images before giving it to FOP. This also seemed pretty straightforward, however our various users can setup stylesheets for these id cards however they want and using "pt" and "in" sizing in them seems to be pretty common...I don't know of any good way to map that to a pixel resizing.
If anybody has any insight into the root cause, ways to make these work arounds work, and/or another idea, you'd be in my debt.
Most certain explanation:
image corruption? it's a bug.
Why not use 0.95? Sooner or later you have to upgrade, Apache consortium won't
fix bugs in 0.25.x versions.
You can't hope to find workarounds for every bugs which might occur in future.
I ended up doing the second thing I mention in the original question...i.e. resizing it before giving it to FOP. I found that I could retrieve the dpi of the printer I was printing to and do some math on it to get pixel sizing. Seems to work perfectly in all my testing...not a real solution but an adequate workaround.

Slowing down the playback of an audio file without changing its pitch?

I am working on an application for college music majors. A feature i am considering is slowing down music playback without changing its pitch. I have seen this done in commercial software, but cannot find any libraries or open source apps that do anything like this.
Are there libraries out there?
How could this be done from scratch from various file formats?
Note: I am working in java but am not oppossed to changing languages.
Timestretching is quite hard. The more you slow down or speed up the sound the more artifacts you get. If you want to know what they sound like listen to "The Rockafeller Skank" by Fat Boy Slim. There are a lot of ways to do it that all have their own strengths and weaknesses. The math can get really complex. That's why there are so many proprietary algorithms.
This page explains things a bit clearer than I can and links to the Dirac library.
http://www.dspdimension.com/admin/time-pitch-overview/
I found this link for java code to do pitch shifting/timestretching
http://www.adetorres.com/keychanger/KeyChangerReadme.html
I use soundstretch to speed up podcasts which is works quite well, haven't tried it on music though.
This site explains how it's done in the physical world:
http://www.wendycarlos.com/other/Eltro-1967/index.html
I don't know how you would emulate that in software though... I'll keep looking
One way to do it would be to double the sampling rate without changing the sampling rate of your source. (Low quality example, but easy to implement. Note: You can also decrease the sampling rate as well).
Check out any math related to phase vocoders.
Another common method is to create an array of fft bins that store data for scheduled intervals of your sound. Then you can choose how quickly to iterate through the bins, and you can re-synthesize that audio data for as long as you choose thus enabling you to stretch out one short segment of your sound for as long as you like.
audacity does it out of the box and it's free. THere are several plug ins for mp3 players as well that are free. Apparently it's pretty easy to do with an mp3 since it's already coded in the frequency domain.

Java VNC Applet vs Screen Capture

I am trying to make an application in which one component captures the screen of the user (for screen casting). I am aware that there are two options to achieve the same using a Java applet (please correct me if I am wrong). First is to use the java applet to take screen shots continuously and convert it into a video and upload it as a video file. And second is to create a java vnc server and record it as a .fbs file and play it using a player like: http://www.wizhelp.com/flashlight-vnc/index.html
I would like to know the best solution in terms of video quality, file size, cross-platform compatibility (windows and mac), firewall problems and finally ease of implementation.
I am very new to Java. Please tell me whats the best solution for my problem. Also, is it easy enough for me to program it on my own or should I get it developed via a freelancer. I have tons of programming experience (5+ years in LAMP) but none in Java.
Thank you very much.
I agree that this is pretty hard. I implemented those two solutions (VNC and onboard screen capture) plus a third (capture from an external VGA source via an Epiphan grabber) for a former employer. I had the best bandwidth-to-quality ratio with VNC, but I got higher framerate with VGA capture. In all three cases, I reduced the frames + capture times to PNGs and sequenced them in a QuickTime reference movie. Then I made flattened video (MPEG4 or SWF) of the results. In my case, I then synchronized the screen video with a DV stream.
In the end the technology worked (see a sample of the output) but our business model failed.
From what I know, the older versions of applet had security restrictions that may not allow for screen capture. Instead, a java application may be feasible.
Regarding the build-it-yourself vs the fire-a-coder, it depends on how you value your time compared to what you can find on a freelancer site.
I think you can find someone from India/Romania/Poland/Other countries that can make it for an affordable price
Given your Java knowledge and the difficulty of the task, have you considered taking an alternative approach? For example, how about a native VNC server for the end-user, which is just a small download and then they click "Run." And that native server is programmed to capture the screen and send it straight to your web server, which has a client like vnc2swf or other means of converting the VNC stream to a video or .fbs file? Does all that make sense?
Admittedly, without Java, you have to prepare one executable program per platform you want to support, however, I don't know. That still sounds easier to me. Consider Copilot.com. They are doing VNC but they still use small native apps for each platform.
Sorry but this seems the kind of job that requires a lot of experience. Even if you find code snippets all around the net to fix this and that, the overall result may be way worse than simply hiring an experienced Java programmer.

Categories