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


HP-Agilent-Keysight 41951-69001/ 41951-61001 Impedance Test Adapter for 41951A picture

HP-Agilent-Keysight 41951-69001/ 41951-61001 Impedance Test Adapter for 41951A

$350.00



Fluke  845AR High Impedance Voltmeter-Null Detector picture

Fluke 845AR High Impedance Voltmeter-Null Detector

$500.00



New Tonghui TH2810D LCR Meter Digital Eectrical bridge impedance measurement picture

New Tonghui TH2810D LCR Meter Digital Eectrical bridge impedance measurement

$499.00



Tenma 72-6947 Audio Impedance Tester picture

Tenma 72-6947 Audio Impedance Tester

$99.50



BECO Universal Impedance Bridge Model 315A, Brown Electro Measurement Corp. 315A picture

BECO Universal Impedance Bridge Model 315A, Brown Electro Measurement Corp. 315A

$129.99



Vintage Organic Impedance Measuring Control Panel AC-4 by CEFCO EXPERIMENTAL picture

Vintage Organic Impedance Measuring Control Panel AC-4 by CEFCO EXPERIMENTAL

$199.99







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