smart solutions for small devices
[ start | index | login ]
start > Fun > Send PC screen to SU2

Send PC screen to SU2

Created by bjoernQ. Last edited by bjoernQ, 4 years and 360 days ago. Viewed 1,578 times. #1
[edit] [rdf]
labels
attachments
Here a java code snipped that takes a screenshot of your PC desktop and sends it to a Nokia SU-2 (or any other bluetooth JPEG viewer ...)

package scr2su2;

import de.avetana.javax.obex.ClientSession; import de.avetana.javax.obex.HeaderSet; import de.avetana.javax.obex.Operation; import de.avetana.obexsolo.OBEXConnector; import java.awt.Rectangle; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import javax.imageio.ImageIO;

public class Main {

/** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here try{

for(int j=0;j<100;j++){ // 100 times change this java.awt.Robot roby = new java.awt.Robot(); Rectangle screenRect = new Rectangle(0,0,640,480); // SU2 can only handle images up to VGA resolution BufferedImage img = roby.createScreenCapture(screenRect);

ByteArrayOutputStream baos = new ByteArrayOutputStream();

ImageIO.write(img, "jpeg", baos );

// change the address to the bluetooth address of your SU2 String adr = "btgoep://0002EE9340ED:13;authenticate=false;encrypt=false;master=false";

ClientSession cs = (ClientSession) OBEXConnector.open(adr); HeaderSet hs = cs.connect(cs.createHeaderSet());

byte[] text = baos.toByteArray();

hs.setHeader(HeaderSet.NAME, "test.jpg"); hs.setHeader(HeaderSet.TYPE, "image/jpeg"); //hs.setHeader(0x49, text); // if everything fits inside a packet, the data can be packed in the PUT command hs.setHeader(HeaderSet.LENGTH, new Long(text.length) ); Operation po = cs.put(hs); System.out.println("put...."); java.io.OutputStream os = po.openOutputStream(); int of=0; do{ int le = 64; if(le+of>text.length) le=text.length-of;

os.write(text,of,le );

os.flush(); of+=le; }while(of<text.length);

po.close(); cs.disconnect(null); cs.close();

// you should add a Thread.sleep(..) here because SU2 can't handle that otherwise

}

} catch (Throwable e) { e.printStackTrace(); }

}

}

The code above needs BlueCove and AvetanaOBEX in your classpath to work. You should change the bluetooth address to the address of your SU-2.

Now you can watch your PCs desktop on your TV.

Sending stuff to your SU-2 you should send the bytes in small chunks and set the type to image/jpeg.

Please login to post a comment.
www.mobile-j.de | Bjoern Quentin