After going through many similar looking questions I had no way but put my own question here.
I need to display an image on swing application. The source of image is bitmap data which is retrieved from MS SQL server. I have tried the following ways
TRY 1 - I have tried creating an ImageIcon from the bytes retrieved. No results.
TRY 2 - Saved the bytes in a .png file and tried loading Using ImageIO. This works fine on my local machine but fails on test server. Both are windows machines.
TRY3 - On step 2 I tried saving in different formats than .png. It does not work at all.
Please let me know what am I missing?
NOTE : I have tried including jai jars into the Referenced Libraries also.
You should have stored a hint what format the data has in the database. If not, you can only hope that ImageIO can handle it.
There is no need to write the data to files (which is a pitfall in itself, where would you write them? Think of restricted process privileges and disk quotas). Just create an InputStream that accesses the data directly (e.g. java.io.ByteArrayInputStream), that way you can have ImageIO load directly using the stream based methods.
Related
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 found a problem when loading a bitmap file in my working company software. It crashes the software when I drop in the bitmap file. However, I am trying to create a Java app to read the bitmap file header and display the header information. So I know what might causing the problem.
Can anyone suggest the idea how can I grab the bitmap file header information or which class should I use to achieve this goal?
Yes it is possible, I wrote code to do something like this with jpeg headers some months ago.
Basically, you need to learn a bit about the bitmap file format.
Then you need to open the file (for reading bytes).
Finally, you read enough bytes to get to the right field in the header, and decompose that to the Java data type you want.
There may be a class that already does this, in which case I would suggest Google for finding it.
The apache sanselan project provides a BmpImageParser class for parsing BMP files. You can take a look at the source here.
I need to make a data file to hold two empty tables with many fields
I have been successful at making a MySQL 5.5 Table with its DOS style IDE OK.
And MySQL registers with NetBeans very well.
Can I make a script to build this from with in my program
or can this be done directly in Java and get a Java file to read file parameters as its executed to create the data base file name.
I have no idea what direction to take to do this and what's possible.
I'm writing in Java and Delphi and Delphi has no MySQL support.
Has any one done anything similar before and how did they do it
The database is to hold 70 meduim size pictures, How slow will updates be when accessing pictures and should I use JPEG or BMP storage for wireless Java apps?
Can Java manage JPEG files and display them?
Lots of questions in one post. Let me try to address each point individually.
Yes, you can write Java code to create your MySQL database for you. On the other hand, tools such Liquibase can do this for you—you just need to learn its XML configuration syntax.
Lots of people have successfully written Java and Delphi code to access MySQL databases. If I recall correctly, at the very least Delphi supports MySQL access through ODBC, if not, through 3rd-party custom components.
Java can store & retrieve JPEG images to/from a database just like any other language, though, in practice, I wouldn't do it that way. Rather, I'd store the images themselves in the file system and just store their locations in the database. RDBMSes weren't really built with handling large binary BLOBs in mind.
How would you like to display the images? If on screen via a desktop client, then, yes, Java's Swing components can easily and readily display JPEG, even GIF & PNG images. If via a Web browser or remote client, then it's really just a matter of serving the images over HTTP to the browser/client app.
Right now I'm facing some performance issues in a web app because of a situation with Oracle saving images and my webapp getting them.
The database where the image is stored gets it from a Oracle Forms' form, which allows user to save some data along the image (as a BLOB). No matter the format you choose as input, it gets saved in a table with its description and stuff, with the corresponding field getting the image is a BLOB.
Now going to the webapp, it reaches the table through a web service querying a stored procedure and a Java WS client, so my webapp gets the image and saves it in the webapp's server's temp folder while needed. The output does not get any particular extension because the DB doesn't tell which extension should it be. Anyhow, the broswer can tell using the metadata. A brief schema of the process goes as follows
Presentation layer <--- Business logic <--- WS Client ---o)--- WS <--- Stored Proc <--- BLOB column
My problem is: how can I avoid the DB serving a bitmap? The performance is awful in specific situations and poor connections because of loading a 1.5MB bitmap. And this webapp must be able to work properly in 256Mb connections. What can be done, then?
Thanks for your help.
Edit: The thing can be treated using BFILE datatype. Thanks for your help. (2010/10/20)
Edit2: The images are uploaded to the database thru a client/server system build in oracle forms (6i/10g). The form itself is the one who stores the image as a blob in the table, transforming it into a bitmap, doesn´t matter if the uploaded image is a light jpg (2011/12/07)
Not sure at which layer you actually want to handle things.
If it is the database layer, then I suspect you need to start using ORDSYS.OrdImage datatypes, and you can them make use of the built-in format conversion operations to turn BMP to JPG or whatever.
Also consider is the problem with large bitmaps or with large image files in general.