C#取出SQLServer中为image类型的数据后强制转换为byte数组,然后用convert的base64编码方法编为string;
Java端:
byte[] b = Base64
.decode(String类型, Base64.DEFAULT);
Bitmap bitmap = BitmapFactory.decodeByteArray(b, 0, b.length);
File file = new File(PubData.instance().appDir + "/"
+ images.get(i).getSmuId() + ".png");
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
FileOutputStream stream = null;
try {
stream = new FileOutputStream(file);
bitmap.compress(CompressFormat.PNG, 100, stream);
stream.flush();
stream.close();
} catch (Exception e) {
e.printStackTrace();
}
加载图片:
Bitmap bitmap = BitmapFactory.decodeFile(PubData.instance().appDir + "/" + smuId + ".png");
imageView.setImageBitmap(bitmap);