BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 01-11-2009, 06:43 AM   #1 (permalink)
New Member
 
Join Date: Jan 2009
Model: 8800
PIN: N/A
Carrier: /
Posts: 2
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Image to BlackBerry over socket connection

Please Login to Remove!

Hi!

I'm develompin BlackBerry application for stock values. I'we alredy have server and my blacbkerry connected to this server over socket connection

connection to server:
private String URL = "socket://localhost:64208;deviceside=true";
connection = (StreamConnection)Connector.open(URL);
_out = new OutputStreamWriter(connection.openOutputStream());
_in = new InputStreamReader(connection.openInputStream());

Connection is working fine (sending strings to server and back).
Now i want to display stock value chart on blackberry. I generate chart image on my server (BufferedImage) (can allso generate other type of image if i want) so now i wonder how to send image from server to blackberry usnig my stream connection and display this image on blackberry (BitmapField component).

It would be nice if someone gave me example how to do this.

ty!
Kristjan
Offline  
Old 01-17-2009, 05:26 AM   #2 (permalink)
New Member
 
Join Date: Jan 2009
Model: 8800
PIN: N/A
Carrier: /
Posts: 2
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

after days of work i finaly made it
here is tehe code:

Server side
Code:
//  pout is print writer...
Socket s = ss.accept();
OutputStream os = s.getOutputStream();
PrintWriter pout = new PrintWriter(os, true);
//


// this is our buffered image
BufferedImage slika;
                                     
ByteArrayOutputStream bas = new ByteArrayOutputStream();
ImageIO.write(slika,"JPEG", bas); // write image into ByteArrayOutputStream
byte[] data = bas.toByteArray();
pout.println(String.valueOf(data.length));  // sending image length to blackberry
os.write(data, 0, data.length); // sending image to blackberry
os.flush();

Code on blackberry:

Code:
//
InputStream is
//

// get image size from server
String answer3 = "";
char k3;
do
{
    k3 = (char) _in.read();
    answer3 = answer3+ String.valueOf(k3);
}while(k3 != '\n');

int velikost = Integer.parseInt(answer3.toString());

byte[] data = new byte[velikost];
is.read(data, 0, velikost);   // read image             

EncodedImage image = EncodedImage.createEncodedImage(data,0,data.length);
Bitmap b = image.getBitmap();
BitmapField picture = new BitmapField(b);

mainScreen.add(picture); // adding picture to main screen
Offline  
Old 02-02-2009, 05:41 AM   #3 (permalink)
New Member
 
Join Date: Sep 2008
Model: 8100
PIN: N/A
Carrier: Vodafone
Posts: 8
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi i too tried receiving image from server using sockets am getting the image using ur code, but the transfer speed is too slow. A 10kb image is taking around 40 seconds. Is this a normal socket speed? If not is there anyways to improve the data transfer speed. (Am using InputStreamReader and its read() method is wat s taking time). I now need to tranfer 2Mb data which at this speed would be highly impossible.

Thanks & regards
Mike.
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

20Pcs Max7219cng Max7219 Dip-24 Driver Led Display 8Dgt New Ic A
$12.87
20Pcs Max7219cng Max7219 Dip-24 Driver Led Display 8Dgt New Ic A picture2Pcs Sem2005 Sop-16 Ic New Q
$2.53
2Pcs Sem2005 Sop-16 Ic New Q picture10Pcs Af4502 Af4502c 4502 Sop8 New Ic F
$1.58
10Pcs Af4502 Af4502c 4502 Sop8 New Ic F picture5Pcs 74Hc574n 74Hc574 D-Type Flip-Flop Dip-20 Ic New Y
$1.51
5Pcs 74Hc574n 74Hc574 D-Type Flip-Flop Dip-20 Ic New Y picture30Pcs Do-41 Diode 1000 1N4730a 3.9V 1W Zener New Ic W
$0.99
30Pcs Do-41 Diode 1000 1N4730a 3.9V 1W Zener New Ic W picture






Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.