BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 01-11-2009, 06:43 AM   #1
onej
New Member
 
Join Date: Jan 2009
Model: 8800
PIN: N/A
Carrier: /
Posts: 2
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
onej
New Member
 
Join Date: Jan 2009
Model: 8800
PIN: N/A
Carrier: /
Posts: 2
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
mikeaug
New Member
 
Join Date: Sep 2008
Model: 8100
PIN: N/A
Carrier: Vodafone
Posts: 8
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



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


1PC USED A54MA55B BC186A413G52 Mitsubishi A500/F540 Series 55KW Drive Board #CZ picture

1PC USED A54MA55B BC186A413G52 Mitsubishi A500/F540 Series 55KW Drive Board #CZ

$317.00



Mitsubishi FR-A540-0.75K-NA AC DRIVE INVERTER 1 HP 380-480 VAC 50/60 HZ 4.1 AMP  picture

Mitsubishi FR-A540-0.75K-NA AC DRIVE INVERTER 1 HP 380-480 VAC 50/60 HZ 4.1 AMP

$649.99



1PC USED A54MA30B Mitsubishi F500/A500/A540 Series 30-37KW Drive Main Board #CZ picture

1PC USED A54MA30B Mitsubishi F500/A500/A540 Series 30-37KW Drive Main Board #CZ

$255.00



Radiomatic Flo-One Beta Radio-Chromatography Detector A-500 Model A525 [E2FL] picture

Radiomatic Flo-One Beta Radio-Chromatography Detector A-500 Model A525 [E2FL]

$245.00



A54MA55B and BC186A413G52 frequency converters A500/F540 series 55KW drive board picture

A54MA55B and BC186A413G52 frequency converters A500/F540 series 55KW drive board

$350.00



Mitsubishi A500 Variable Freq. Drive VFD AC Inverter 480V 3 PH 6.7A 3 HP Max picture

Mitsubishi A500 Variable Freq. Drive VFD AC Inverter 480V 3 PH 6.7A 3 HP Max

$299.99







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