Convert Image 2 byte array and then ....

Hi all,

i am try 2build program like windos remot control that allowed u to watch on anther user desktop.

for that i need 2 send a lot ImageCapture of the Desktop

to capture the screen of the Desktop i do like that :

BufferedImage screencapture = new Robot().createScreenCapture(

new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()) );

now i need to send this Capture code from the server 2 the Claint

and for sending Images i need convert them 2 Bytes

and this i do like that:

int[] pix = new int[screencapture.getWidth(null) *

screencapture.getHeight(null) ];

for(int j=0;j<screencapture.getHeight(null); j++)

for(int i=0;i<screencapture.getWidth(null); i++)

pix[i*j]=screencapture.getRGB(i,j);

as u can see now i gotint array of the Image ( or not ? )

now i convert this int arry to byte array like that

byte[] matrix= (new Converts()).convertIntArray2ByteArray(pix);

Converts is a Class that i build have a lot method of Converts

1 of the Method is "convertintArray2ByteArry"

this method get int array and return byte array here the code:

public byte[] convertIntArray2ByteArray(int pix[])

{

byte[ ] pixels =new byte [ pix.length *4];

for( int j= 0 ; j >< pix.length ; j++ )

{

pixels[4*j]= (byte)(pix[j]);

pixels[4*j + 1] = (byte)(pix[j] << 8);

pixels[4*j + 2] = (byte)(pix[j] << 16);

pixels[4*j + 3] = (byte)(pix[j] << 24);

}

return pixels;

}

after all this story i guss i got byte array from the CaptureImage.

( like printscreen that i capture the image)

and after all the converts ( BufferImage>Int Array > Byte Array)

i will have 2 send it to anther PC ( Claint) and 2 draw it

but lets say i send it now i got this Byte array in the other PC

and i want save it as JPG file so i do like that :

( matrix is the name of the Byte arrayf \ the image so i need 2 convert

him back 2 image and save it 2 file look how i do in the following code )

Image image= Toolkit.getDefaultToolkit().createImage(matrix);

i use Java Toolkit to creat image from the array byte

now i need 2 convert the image 2 BuffImage for save it 2 file i do like that

BufferedImage bi = Converts.convert(image);

"Converts.convert(image)" is a method in my class that i build

the Method going like that :

public static BufferedImage convert(Image im)

{

int imgHeight=im.getHeight(null);

int imgWidth= im.getWidth(null) ;

BufferedImage bi = new BufferedImage( 1024 , 768 , BufferedImage.TYPE_INT_RGB);

Graphics bg = bi.getGraphics();

bg.drawImage(im, 0, 0, null);

bg.dispose();

return bi;

}

and now only need save to a file like that :

File file1 = new File("im121ag.jpg");

ImageIO.write(bi,"jpg",file1);

ok that all the story now i say what is tMY problem

when i go and open the JPG File that i have been Create

its Show Picture of Black Screen ;((

and i dont know why ;-(

if some 1 know where i mistake in my code or if i missed somthing

or have short code or any Advise i will Glad 2 hear TY ALL

[3338 byte] By [Tog007a] at [2007-11-26 14:04:06]
# 1
hi,me too having the same problem.anybody know this answer please reply the same.Pradeep
pmmpmma at 2007-7-8 1:47:54 > top of Java-index,Security,Cryptography...
# 2
1. There are errors in the code.2. It's a better idea to compress to JPEG on the server side and send the bytes to the client.
Rodney_McKaya at 2007-7-8 1:47:54 > top of Java-index,Security,Cryptography...
# 3
hi,me too having the same problem,any one know the solution please let me know ASApregardssree
gold_chaira at 2007-7-8 1:47:54 > top of Java-index,Security,Cryptography...