我刚刚开始将图像从本地主机数据库上传和检索到 android。我怎样才能做到这一点 ?我已经尝试思考了三(3)天,但我不知道如何编码。事情是这样的:
- 如何从 android 模拟器 --> 本地数据库保存图像?
- 如何从 localhost 数据库 --> android 模拟器获取图像?这样,每当我打开 Android 应用程序时,它都会显示我上传的图像(仅 1 张图像)..
最佳答案
上传之前首先将图像更改为 byteArray
ByteArrayOutputstream bos;
Bitmap bm ;
byte[] bitmapdata,bb;
bm= BitmapFactory.decodeResourses(getResources() ,R.drawable.image);
bos = new ByteArrayOutputStream();
String convert_txt;
当图像以字节形式存储在数据库中时,尝试从数据库获取图像
bitmapdata = bos.tobyteArray();
for(int i =0 i<bitmapdata.length ; i++){
convert_txt = convert_txt+bitmapdata[i];
}
Cursor cursor = dh.rawQuery("Select statement....");
bb = cursor.getblob(cursor.getColumnIndex("columnanme"));
关于php - 如何从本地数据库(mysql)获取上传的图像到android?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26249357/