Array of bytes and KSOAP2

Hello
I have a request. I have a MSSQL database into two columns. One is a varchar and the second is the Image type. I would use these two fields filled to KSOAP2. I tried to send a picture in KSOAP byte array but it did not, probably, I sometimes confuse.
Here is the source code.

public byte[] getBytesFromBitmap(Bitmap bmp) {
 try {
  int height=bmp.getHeight();
  int width=bmp.getWidth();
  int[] rgbdata = new int[width*height];
  ByteArrayOutputStream bos = new ByteArrayOutputStream();
  DataOutputStream dos = new DataOutputStream(bos);
  bmp.getARGB(rgbdata,0,width,0,0,width,height);
  for (int i = 0; i < rgbdata.length ; i++) {
   if (rgbdata[i] != -1) {
    dos.writeInt(i);
    dos.flush();
    //l++;
   }
  }
  bos.flush();
  return bos.toByteArray();
 } catch (Exception ex) {
  Dialog.alert("getBytesFromBitmap: " + ex.toString()); return null;
 }
}

Bitmap borderBitmap = Bitmap.getBitmapResource("rounded.png");
byte[] img = getBytesFromBitmap(borderBitmap);
String name = "Name";
SoapObject rpc = new SoapObject(serviceNamespace, "name");

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
rpc.addProperty("_img", img);
rpc.addProperty("_string", name);
envelope.setOutputSoapObject(rpc);
envelope.bodyOut = rpc;
envelope.dotNet = true;
envelope.encodingStyle = SoapSerializationEnvelope.XSD;

I also tried... I transferred the image in the array of bytes to a string, using the string, I sent KSOAP and everything went well... The problem was that if she string converted to array of bytes, and then in a Bitmap, then bb do not show Bitmap. I would like to send a byte array.

Thank you

Stepan

This function is useful to get the bytes of the image.

public static byte[] returnByte(String path)
{
FileConnection fconn;
int available = 0;
InputStream input = null;
byte[] data=null;
try
{
fconn = (FileConnection)Connector.open(path);
if(fconn.exists()==true)
{
input = fconn.openInputStream();
available = input.available();
int fSz = (int)fconn.fileSize();
data = new byte[fSz];
input.read(data, 0, fSz);
}
}
catch(Exception e)
{
Dialog.alert("Error");
}
return data;
}

Now you must do this:

Byte [] img = returnByte ("pawan.png");

rpc.addProperty("_img", Base64.encode(img));

I'm sure it works...

Thank you

Tags: BlackBerry Developers

Similar Questions

  • Make Image more using the Web Service and Ksoap2

    Hey all, I was wondering if someone can help me with a problem. I use a .net web service that grows on a collection of person objects when a person runs a query from the blackberry phone. To implement this I'm using ksoap2. In my service, I'll send in a string as a parameter. I returned the collection of people that contain the firstname, lastname, address, race, sex. I also try to send a picture. Now, I got this works very well when you do not include the image settings.  In my class on the side of .net in person my class, I have 'image' public property which is a string. I get the bytes of the image and convert it to a base 64 string:

    MemoryStream ms = new MemoryStream();

    System.Drawing.Bitmap.bmp = new System.Drawing.Bitmap (imagePath);

    BMP. Record (MS, System.Drawing.Imaging.ImageFormat.Bmp);

    p.Image = Convert.ToBase64String (ms, GetBuffer());

    BMP. Dispose();

    Mrs. Close();

    Note: in my outings, I see the 64Encoding string.

    On the side of blackberry, I have:

    Byte [] imageArray = ((person) personVector.elementAt (i)).image.getBytes ();

    EncodedImage = bitmap

    EncodedImage.createEncodedImage (imageArray, 0, imageArray.length);

    gridMgr.add (new BitmapField (bitmap.getBitmap ());

    Unfortunately, my number of vector appears as empty and I keep get get a parse error. As I mentioned before, if I remove ownership of the Image on both sides, it works like a charm.  I tried to use just about everything. Any ideas on how to overcome the image using ksoap? I tried to make the image property in the two classes as arrays of bytes, but he had no success. My problem when you use the byte array was in the class of person on the side of the blackberry for the PropertyInfo, that I didn't know what to use (for example STRING_CLASS, OBJECT_CLASS, LONG_CLASS); in any case, neither worked. What do you suggest me?

    I was able to do successfully the bytes of the image the device in the following way in my seriealize class.

    In the getProperty method, I use the following:

    info.type = MarshalBase64.BYTE_ARRAY_CLASS;

  • Array of bytes to the Type specifier

    Hello everyone.

    In my project I have a connection to an external device via a RS-232 connection. Now, I read the bytes and want to convert them to a specified type, such as I32 or U8.

    When the data arrives, I convert the string to a byte array. For one serving, I need to convert an array of 4-byte an I32. This means that the bytes are literary the data to be converted to the data type.

    I have no idea how to do this, pourriez is it you guys please help me?

    Kind regards

    Jesse Bax

    Swissdrones of operations AG

    STH says:

    That's exactly what about built-in 'contact numbers.

    It's too much work.  Simply create a cluster of all data in the message and Unflatten string will do everything for you.

  • How to convert an array of bytes in a single integer

    Hello!

    So, for the moment, I am trying to receive data from a device that sends data back as an array of 10 bytes, where the first 2 bytes are a header, 6 are a number of words that is supposed to be a unique 48-bit value and the last 2 are a number of errors which is suppose to be a unique 16-bit value.

    Ex:

    Word has received

    (Header)   (----------------------------------Word Count------------------------------)   (Number of errors)
    0            120     0               44              221          155          96             48             0              0

    So, in theory, what I want to do is be able to calculate the values like this:

    (Header)   (----------------------------------Word Count------------------------------)   (Number of errors)
    0            120     0               44              221          155          96             48             0              0
    The binary values: 00000000 00101100 11011101 10011011 01100000 00110000 00000000 00000000
    Concat. Vals: 000000000010110011011101100110110110000000110000 0000000000000000
    Calc'd Vals: = 192696508464 words = 0 errors
    * 40 (40-bit words)
    Totals: = 7.7078603e + 12 bits total = 0 Total errors

    But the problem that I am running is that all methods that I use seem to not be correct.

    I tried:

    Flatten the data and then it unflattening like a U64

    Convering to bool, concatinating tables data, and then convert that to a certain number

    Join all the bytes together using the join function

    Casting to an array of bytes to a U64

    And with all methods, the data that I use is incorrect (in the sense where the values are incorrect compared to this calculation manually like I did above), and at this point, I'm not sure how to get the correct values, so any kind of help would be greatly appreciated!

    Thank you!

    It seems to work for me...

  • What is the best way to convert an array of bytes or string cluster

    I am writing a program that sends UDP packets and I defined the data I want to send via large groups (with numbers of u8, u16/u32, u16/u8/u32 tables and nested groups). Just before sending the data, I need to convert groups or chains of arrays of bytes. The flatten the string function is almost perfect for this. However, it is addition of lengths in the tables and strings that makes this unusable method, because as far as I can tell.

    As I have many of these groups, I would rather not hard code the unbundle names and conversion/cast of strings or arrays of bytes for each of them.

    Y at - it a function, or a tool that I'm on?

    Thank you!

    mkirzon wrote:

    The program I'm developing is to communicate and to poll an external device that includes a Protocol well documented. The messages that I built in clusters contain components accurate that expected from the other device. So, if my program adds any additional info (such as this array/string lengths), monitor the device external won't recognize messages and returns an error.

    Unfortunately, you have to ungroup your cluster and collect the individual channels to concatinate.

  • Problem of cast to array of bytes in array of float

    Can someone help me find this process I am doing wrong?

    • I read a string of 6 tanks during the series.
    • I take the string and convert it to an array of bytes.
    • I then reverse the byte array because my microcontroller first sends the LSB and Labview is Big-endian
    • I catalogued this table in an array of float
    • I invert the table again to retrieve the data in the original order

    I can see the bytes in the array of bytes as 'byte, 0, 0, 0' when there are a small number, but when I I cataloged get very large or very small floats. Can someone help me understand this?

    Thank you!

    LabVIEW 2011

    You should probably use string unflatten, select the byte with rule of the little order and use a DBL 1 d array type. Everything must fall in place without all these gynastics bit, what you're doing.

    You can show us your code? I don't understand your use of "decimate the table."

    Attach a small VI containingh a typical chain received as a constant of diagram.

  • Array of bytes to double signs for AutoPowerSpectrum

    I'm trying to analyze a wav file and get the thd.

    During the read wav file, I read in one data (void *) table.  And according to the type of bit, depends on how to call PlotWaveform.  So, in my example, I have a 16-bit mono signal.  And I'm calling draw the waveform as follows:

    PlotWaveform (panelHandle, PANEL_CHANNEL_LEFT, channel1, samplesPerChannel, type, 1.0, 0.0, 0.0, 1.0, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1,
                            VAL_RED);
    

    And a perfect sine wav out.

    Now, I try to do the THD on the signal, but can't convert my array of bytes in a double table.  I have the following code, but all my values that I use are in power - 319th.

    channel 1 is a (void *)

    I guess that the ConvertArrayType () function can help you in this problem.

  • Large array of bytes sent via socket?

    Hello

    I have had this problem for a while and have never really stood under how to solve it properly. I don't understand how you are supposed to transfer arrays of bytes that are larger than the size of the buffer of the socket. I have semi overcome them chapter by chapter from the table and write through the sleeve and reassemble frequently on the other side, but this causes problems. What is the right way to send a byte array that is larger than the buffer socket on an outputstream?

    I suspect that I am thick here, but I'm not aware that there is something called a socket buffer.  Actually, let me rephrase.  I'm not aware that there is a specific size that was a little to the amount of data to a socket can accept.

    And you should, in theory, be able to send constantly bytes on a socket and the IP protocol should ensure that they arrive in the right order, at the other end, providing the connection is maintained.

    In practice there are limits, but I wasn't aware of a buffer size of socket specific related to the shots of Blackberry (or any Sockets besides /).

    The original poster might explain what determines the size of this buffer?

  • Array of bytes to bitmap

    I'm trying to convert an array of bytes into a bitmap image.  The byte array returned from a url, if you enter the url in Internet Explorer, it is automatically returned.  What would be the best way to get the data returned by the url, and how would it be better to convert as bitmap?

    There is an example here:

    http://www.coderholic.com/BlackBerry-webbitmapfield/

  • Sending the command apdu with an array of bytes as CDATA

    Hello
    I learn the java card as part of my final year project. So far I think I can do the most basic things, but I stuck a special moment.

    I know that there are different manufacturers to create an apdu command object and a number of these manufacturers take an array of bytes as CDATA values.

    My problem is, how do I access this data table in the side of the card because apdu.getBuffer () returns an array of integers (bytes)? And what is actually on apdu.getBuffer () [ISO7816. (Instead of OFFSET_CDATA)] when you send the apdu command object using such constuctor?

    concerning

    Published by: 992194 on 6 March 2013 06:12

    992194 wrote:
    (..) I should have mentioned earlier that my card use jc 2.2.1 version, and from different places, I've read that this version does not support ExtendedLength facilities.

    Indeed.

    I also understand the semantics of apdu.getBuffer () [ISO7816. OFFSET_CDATA] is the first byte of the data command. My question is, these command data was initially provided as an array of bytes. Something like this:

    + new CommandAPDU(CLA, INS, P1, P2, DATA_ARRAY, Le) +.

    For example, when you call:

    ubyte [] buffer = apdu.getBuffer)

    So it means that the values of bytes inside the tableau_donnees argument automatically occupy locations + buffer [ISO7816. OFFSET_CDATA] + inside the buffer?

    Yes. The length would be (abstract) (buffer [ISO7816. (OFFSET_LC] & 0xFF) . Notice the & 0xFF is a must greater than 127 bytes.

    Or there is a mechanism to extract the table tableau_donnees itself?

    Laughing out loud

    In fact, in the interest of performance and portability in environments with low memory, usual coding style must pass buffer , an offset that and length; rather than take an object, which would require a copy. Welcome to the real world of Java Card.

  • HP EliteBook 840 G3: Laptop HP 840 G3 have byte and build id

    have byte and build IDs for HP EliteBook 840 G3 to change motherboard

    AVAILABLE: 15WWCSBA601 #SABV (case sensitive) #DABV

    FB: 3X476J6S6b757H7M7Q7W7saBaEapaqauawbPbSbU bhcAcedQ.RD (respect for case-sensitive)

    HP assistance form

  • What, if any, is the relationship of bytes and pixels?

    Digital photos IRT. Having problems sending a fairly large image file (JPG) photo to a recipient to pass on my Web site.

    Hello

    Ask the developer to explain what he needs from you.

    Byte - a unit from the date of the computer usually 8 bits form a byte.
    http://en.Wikipedia.org/wiki/byte

    Pixel - an area on a display screen which are used to display an image.
    http://en.Wikipedia.org/wiki/pixel

    Typcally for a B & W each pixel of the image is 8 bits or 1 byte and a color for each pixel Image is 24-bit or
    3 bytes a byte each for red, green and blue). So the more addressed pixels larger the file will be
    be or more bytes required to store the image.

    Read this link:
    http://www.normankoren.com/pixels_images.html

    Check IrfanView which allows to edit the image files and also ask in their forums.

    IIrfanView - free - read, edit, save image and Icond files.
    http://www.IrfanView.com/

    IrFanView - Forums<--- possible="" help="">
    http://en.IrfanView-Forum.de/VB/Forum.php

    I hope this helps.

    Rob Brown - Microsoft MVP<- profile="" -="" windows="" expert="" -="" consumer="" :="" bicycle=""><- mark="" twain="" said="" it="">

  • Link for antimalware bytes and SUPERAntiSpyware?

    Hi, where can I find the official link like cnet or something for Anti - Malware Bytes and SUPERAntiSpyware? Thanks in advance

    Here are the websites of companies:

    http://www.Malwarebytes.org/products/malwarebytes_free

    http://www.SUPERAntiSpyware.com/

  • Array of bytes in JSON string is not a valid JSONObject.

    I get an array of bytes from a URL that I can view in Google Chrome as a valid JSON object.

    When I get the answer to IOUtilities.streamToBytes (), it returns in the following way:

    [16, 8, 1, 10, 2,... 1, 0, 0, 8, 0, 0, 120, 2, 0]
    

    How can I convert the byte array to a human readable string I can spend in the JSONObject constructor?

    I tried the following character encodings:

    • "ISO-8859-1".
    • 'UTF-8 '.
    • "UTF-16BE".
    • "US-ASCII".

    Hello

    First, check with your http connection that it returns the appropriate response.

               connection=(HttpConnection)Connector.open(url,Connector.READ);
                connection.setRequestMethod(HttpConnection.GET);
                if(connection.getResponseCode()==HttpConnection.HTTP_OK)
                {
                    inputstream=connection.openInputStream();
                    int ch;
                    buffer=new StringBuffer();
                    while((ch=inputstream.read())!=-1)
                    {
                        buffer.append((char)ch);
                    }
                    System.out.println(buffer.toString());
                }
    

    If so, you need to spend just that data in json for parsing.i

    Thankx

  • array of byte size limit]

    I download & save multimedia files (video/pdf) using following code. The question is his works well for small size files MB (1 MB to 18 mb), but for some 60 MB files it stuck during the download. or sometimes download does not start. Thr is a size limit for byte array coz I am booting with the length of the file. This len contains the bytes to be read

    int

    Len = (int) hc.getLength ();

    byte data = newbyte[len];

    if (len > 0) {

    intactual = 0;

    intBytesRead = 0;

    while ((bytesread! = len) & (real! = - 1)) {

    real =

    tell. Read (data, bytesread, len - bytesread);

    bytesRead += real;

    percentage = bytesread * 100;

    percentage = percentage / len;

    int p = percentage (int);

    ProgressIndicatorScreen.

    this.model.setValue (p);

    }

    }

    I don't think that there is a size limit for an array of bytes, this is probably a problem with the connection. Download large files has been difficult for ever.

Maybe you are looking for

  • Cannot start gmail after refusing cookies. How to cancel it?

    I clicked on refuse to accept and now I can connect to gmail, but get a message that the page cannot be loaded. It seems that there is nowhere to re - enable cookies. If I use internet explore, it works again, but I prefer to use firefox

  • order of the shutter with APT driver

    Hello I'm quite new to Labview. I want to remote control a SH1 shutter with controller of tsc001 within a Labview VI. I have seen that we can use activex objects to insert a driver APT in a Labview VI (thorlabs drivers for control of the movement, se

  • What is the problem with my system restore?

    I tried to restore using various available dates and the message is failed to restore. [Transferred from Internet Explorer]

  • Acer Iconia W510 portUSB Tablet

    USB - A on the keyboard works very well. But connection USB key to the connector micro USB Tablet (via adapter USB A/female-microB/male) is quite dead.Any suggestions?

  • How to send pictures in a folder

    Help send pictures please! I downloaded pictures. Place them in a folder. But I can't send the file. When I try it opens the folder of the individual photos.