У меня проблемы с получением сжатого изображения в формате JPEG (хранится в виде BLOB-объекта в моей базе данных).
вот фрагмент кода, который я использую для вывода изображения, которое есть в моей базе данных:
if($row = mysql_fetch_array($sql))
{
$size = $row['image_size'];
$image = $row['image'];
if($image == null){
echo "no image!";
} else {
header('Content-Type: content/data');
header("Content-length: $size");
echo $image;
}
}
вот код, который я использую для чтения с сервера:
URL sizeUrl = new URL(MYURL);
URLConnection sizeConn = sizeUrl.openConnection();
// Get The Response
BufferedReader sizeRd = new BufferedReader(new InputStreamReader(sizeConn.getInputStream()));
String line = "";
while(line.equals("")){
line = sizeRd.readLine();
}
int image_size = Integer.parseInt(line);
if(image_size == 0){
return null;
}
URL imageUrl = new URL(MYIMAGEURL);
URLConnection imageConn = imageUrl.openConnection();
// Get The Response
InputStream imageRd = imageConn.getInputStream();
byte[] bytedata = new byte[image_size];
int read = imageRd.read(bytedata, 0, image_size);
Log.e("IMAGEDOWNLOADER", "read "+ read + " amount of bytes");
Log.e("IMAGEDOWNLOADER", "byte data has length " + bytedata.length);
Bitmap theImage = BitmapFactory.decodeByteArray(bytedata, 0, image_size);
if(theImage == null){
Log.e("IMAGEDOWNLOADER", "the bitmap is null");
}
return theImage;
Моя регистрация показывает, что все имеет правильную длину, но изображение всегда равно нулю.Я думаю, что это связано с моим типом контента.Или, может быть, так, как я загружаю?