wood burning stoves 2.0*
The moose likes Java in General and the fly likes Writing as a JPG file to disk Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Writing as a JPG file to disk" Watch "Writing as a JPG file to disk" New topic
Author

Writing as a JPG file to disk

ram kumar
Ranch Hand

Joined: May 22, 2008
Posts: 146
The Image gets written to disk and says file size also.

But am unable to see the image.

Some one clarify me on this.

I have Submitted the code.

What am doing is -

I am reading a blob as a byte and trying to save it to disk.

it saves to disk but unable to view the image.








Discussion - the powerfull way to excellence!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41114
    
  45
What does "unable to view the image" mean? How are yoo trying to view it, and what happens?

Does the image file have the same size as the bytes array you're retrieving from the DB?

The call to "flush" should occur after the call to "write", not before.


Ping & DNS - my free Android networking tools app
ram kumar
Ranch Hand

Joined: May 22, 2008
Posts: 146

Am using the windows picture and fax viewer to view the file.

it gets saved to disk. it shows the same size as the source image that i uploaded to DB as a BLOB

Am not able to view the image in the picture and fax viewer application like the source image.

i did that with fout.flush() after fout.write().

Still this problem persists
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
If this was my problem I would use a programmer's editor capable of showing the hex value of bytes to look at both the original jpg and the file recovered from the DB and written.

I bet you will see that something has corrupted the data recovered from the DB and it no longer resembles the original.

I use the ultraedit editor - best money I ever spent, but you may find that your existing editor can display byte values.

Bill
ram kumar
Ranch Hand

Joined: May 22, 2008
Posts: 146
William Brogden wrote:If this was my problem I would use a programmer's editor capable of showing the hex value of bytes to look at both the original jpg and the file recovered from the DB and written.

I bet you will see that something has corrupted the data recovered from the DB and it no longer resembles the original.

I use the ultraedit editor - best money I ever spent, but you may find that your existing editor can display byte values.

Bill



Would you just help me in getting some links regarding this.

i google'd but still i need some more information of

1.how to convert a jpg to blob

2.update oracleDB with the blob.

----------

3. retrive the blob

4.save that in disk as a jpg file.
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5


1.how to convert a jpg to blob
2.update oracleDB with the blob.
3. retrive the blob
4.save that in disk as a jpg file.


1.) Save as a ByteArray/ByteStream
2.) Simple Insert/Update statement will do it
3.) Simple select command will do it
4.) Write out as a ByteStream/ByteArray

You really need to look into the File I/O APIs an pay particular attention to _encoding_, e.g. Make sure your encoding is consistent throughout each stage. This article can help and make sure to look at our I/O FAQ


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 860
It seems like you are assuming the bytes in the database are already in the proper format and simply write them to a file. There are many different image formats. Look at this info and see if you can create your own in memory image and write it to disk

http://java.sun.com/j2se/1.4.2/docs/guide/imageio/spec/imageio_guideTOC.fm.html


http://www.jamonapi.com/ - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
ram kumar
Ranch Hand

Joined: May 22, 2008
Posts: 146
steve souza wrote:It seems like you are assuming the bytes in the database are already in the proper format and simply write them to a file. There are many different image formats. Look at this info and see if you can create your own in memory image and write it to disk

http://java.sun.com/j2se/1.4.2/docs/guide/imageio/spec/imageio_guideTOC.fm.html


Finally this code worked successfully !

I dont know what cases it will fail, but it worked Awesome for uploading images to jpg.

Max File Size uploaded is 25.7 kb

From windows file to oracle DB - Use PictureToBLOB2

From BLOB in DB to File at windows - Use BLOBToPicture2











Convert from BLOB to Picture

i used this code :






 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Writing as a JPG file to disk
 
Similar Threads
Uploading and Retrieving images using Java/JDBC
getblob from db, then convert to byte and write to bitmap/jpeg
store and retreive the image from oracle
Retreving PDF File from Database using Java
How to retrieve images from mysql database into a portlet