aspose file tools*
The moose likes I/O and Streams and the fly likes Image Processing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Image Processing" Watch "Image Processing" New topic
Author

Image Processing

subash prasanna
Greenhorn

Joined: Jun 08, 2011
Posts: 8
Dear Sir/Madam,

Firstly, I am sorry if the thread ( my post ) already exist,if so kindly refer me that post. I have searched already about my problem but i could not find solution.

Secondly, i describe about my problem here.
i have to read a image ( which is stored in binary format) from server ( php - xampp) . i am using Applet to read image (binary file) from server and i have to convert into original image then i have to take print out.

Kindly help me out. Thanks in advance.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

Welcome to the Ranch!

The ImageIO class can be used to convert binary data into BufferedImage objects. You can then display these in your user interface; either with custom painting or with an ImageIcon.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
subash prasanna
Greenhorn

Joined: Jun 08, 2011
Posts: 8
Dear Sir,

Thank you for your reply. A image file has been converted into binary ( for security purpose, image will not be sent directly to client(applet) so that image has been converted into binary format ). My applet will listen or by sending request, it will read binary image format file in stream and keep it in applet.

Then i have to convert this binary image file into ordinary .jpg file and take printout.

Hope i explained my problem clearly.

Could you please help me how to solve this problem....i am in need.
Thanks in advance.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

How did you convert the image to "binary"?
subash prasanna
Greenhorn

Joined: Jun 08, 2011
Posts: 8
Dear Sir,

With the above problem , first i started to convert the image into binary (1 | 0 ).
Could you please whether i am using correct way to change image to binary , if so please tell me what to do next to convert binary to ordinary image again.

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

Could you please UseCodeTags next time? It makes your code so much easier to read.


By reading it as an image, then storing it as an image again the quality of the image may become less. It's probably better to open a connection to the URL and copy the bytes into the ByteArrayOutputStream directly:


I sugges you give your file a different extension. "bat" is used for Windows / DOS batch scripts. "dat" is much more common for binary data files.


This is where you're logic goes wrong. The binary file will contain only 0 and 1 bytes. That's right, bytes. You've essentially made your file up to 8 times as big, as now it uses 1 byte for each bit (ignoring leading zeros).

Usually I'd say to use the original file directly, but you don't want to do this because of security concerns. That means that you have to encrypt the file, then decrypt the file again before you convert the file back to an image. You have a crude way of encrypting, but you don't decrypt it back.

Now you use your own, very simplistic encryption. I would take a look at CipherOutputStream and CipherInputStream instead, with a secure encryption algorithm like AES or Blowfish. The advantage is that it adds even more security (you need a key to decrypt), but it also doesn't make your file up to 8 times as big.

If you still want to use your own encryption technique, you should improve it. Make sure that each byte is stored in 8 bytes, not make it dependent on the value. So do not use Integer.toBinaryString(by) but use bit-wise operations:
The decrypting, using a DataInputStream wrapped around the InputStream so you can use the readFully method:
subash prasanna
Greenhorn

Joined: Jun 08, 2011
Posts: 8
Is this code right?(i am new to java ) . It shows error that java.io.EOFException at last, and in generated bin file, there are nul values. what would be the problem

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

You're now trying to decrypt the original image file while you should be decrypting the binary data file you just wrote.
Ramakrishna Udupa
Ranch Hand

Joined: Aug 09, 2013
Posts: 253
Hi,

Where do I get the decrypted file?

My code is:



Thanks:
Ramakrishna K.C
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2289
    
  49
Where do I get the decrypted file?

What do you mean by this? The earlier posts deal with encrypting and decrypting an image. How does your problem relate to the thread?
Yohan Weerasinghe
Ranch Hand

Joined: Oct 07, 2010
Posts: 499

I believe you should not use the word "Image Processing". "Image Processing" is a complete subject, where 90% of the stuff has to be done via C++ and C.


Are you better than me? Then please show me my mistakes..
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41880
    
  63
"Image Processing" is a complete subject, where 90% of the stuff has to be done via C++ and C.

Not sure what you mean by "complete subject", but there's nothing in image processing that can't (and isn't) being done in Java.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Image Processing