I am having issue with writing to a bitmap and jpeg on disk , i have the following code which extract blob from mssql, then i convert it to byte[], after that i try to output it to bmp/jpeg but the system give me error "Exception :java.lang.IllegalArgumentException: im == null!" and the bmp/jpeg file created are all empty with 0 size on disk, please help me guru, thank you
Class.forName(driverName);
con = DriverManager.getConnection(url,userName,password);
stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("SELECT photo FROM xxt Where xx_id='N7V9FS3005421993' and photo is not null");
while (rs.next()) {
Please post all code. What you posted here does not compile. You may have left out parts which are responsible for the exception...if we don't know the details, we can't help you properly.
That said. First check the exception stacktrace. It should show you a line number and class where the exception happened, check if you wrote something wrong in that line. Also, check the results of your database calls! Is the result length == 0? Do you use an empty (or null) array? Log the values you get, to have more information available.
System.out.println("Length"+blobLength);System.out.println("testlen"+blobAsBytes.length); both of the system.out return the size but when arrive at ImageIO.write(image, "JPEG", new File("C:\\sams1\\image.JPG"));, it gives im=null exception error , and the image it produce in the sams1 folder is zero size and empty view
Apparently then the BufferedImage returned by ImageIO.read() is null. I haven't used that API before, maybe it is better/neccessary to create an ImageInputStream with your byte data and use that for ImageIO.read()? Something like
And again, test if the image is null before using it
If no registered ImageReader claims to be able to read the resulting stream, null is returned.
Apparently there's something wrong with your image data. If you save blobAsBytes to a file directly and then try to open it in any image editing / viewing software*, does that succeed?
* most programs look at the actual content, not the file name, so that shouldn't be a problem.