我有一个 android 应用程序,供超市的客户使用。此应用程序应提供商品照片。
照片从 asp.net 网络应用程序上传到 Microsoft sql server 2008 图像字段。然后,移动应用程序将此字节数组作为 xml 字符串接收到手机。之后,这个数组被保存在一个 sqlite db blob 字段中。
现在我的问题是即使我收到一个字节数组我也看不到这些图像。
以下将显示我的代码。
Java Android 保存图片
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.GetImage() 返回一个字节数组。除了位图部分,下表也可以正常工作
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);
- 谁能告诉我该怎么做以及如何解决这个问题?感谢在 提前
最佳答案
Base64 字符串是与 Java 和 C# 通信的最佳方式。这是因为当您将字节转换为另一个字节数组的 blob 时。它可以给出不同的值。
关于java - 如何从从 C# 接收到的字节数组加载图像?安卓应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32645327/