2

I have an android application that is used by customer from supermarkets. This application should provide photos of goods.

Photos are uploaded from asp.net web application to a Microsoft sql server 2008 image field. Then, mobile application receives this byte array to the mobile phone as a xml string. After that, this array is saved in a sqlite db blob field.

Now my problem is I cannot see these images even though i received a byte array.

Following would show my code.

Java Android Saving image

String iid = id.item(j).getFirstChild().getTextContent();
           String iname = name.item(j).getFirstChild().getTextContent();
           String ibrand = brand.item(j).getFirstChild().getTextContent();
           String icategory = category.item(j).getFirstChild().getTextContent();
           String iuom = uom.item(j).getFirstChild().getTextContent();
           String iprice = price.item(j).getFirstChild().getTextContent();
           String iimage = image.item(j).getFirstChild().getTextContent();

           Items t = new Items(iid, iname, ibrand, icategory, iuom, Double.parseDouble(iprice), iimage.getBytes(), true);

I retreive that image to byte array using cursor and following I.GetImage() returns a byte array. Following table is also working fine except bitmap part

ImageView img=new ImageView(this);
           Bitmap bm = BitmapFactory.decodeByteArray(I.GetImage(), 0, I.GetImage().length);

           //DisplayMetrics dm = new DisplayMetrics();
           //getWindowManager().getDefaultDisplay().getMetrics(dm);

           //img.setMinimumHeight(dm.heightPixels);
           //img.setMinimumWidth(dm.widthPixels);
           img.setMinimumHeight(100);
           img.setMinimumWidth(50);
           img.setPadding(20, 20, 20, 20);
           img.setImageBitmap(bm);
           tableRow.addView(img);
  • Could anyone tell me what to do and how to fix this issue? Thanks in advance
  • You go one step too deep. I guess you receive a byte-representation as String. What you are doing is to save the byte-representation of the string of the byte-representation. So instead of de-coding you add another layer of encoding so-to-speak. – Fildor Sep 18 '15 at 07:26
  • This could help you: http://stackoverflow.com/questions/140131/convert-a-string-representation-of-a-hex-dump-to-a-byte-array-using-java – Fildor Sep 18 '15 at 07:31
  • Coming from .net, you have to check the Encoding, too. – Fildor Sep 18 '15 at 07:32
  • would you like to write that as an answer for this? may be little bit more explanation @Fildor –  Sep 19 '15 at 09:12
  • How about using a base64 string not byte array to string from c# side? – gayan1991 Sep 23 '15 at 05:50

1 Answers1

0

Base64 string is best way to comminucate with Java and c#. It's because when you convert byte to blob which is another byte array. It could give different values.

gayan1991
  • 753
  • 2
  • 11
  • 35