从SQLiteDatabase检索到的图像加载到listview android时质量非常差
我将图像转换为字节并保存到数据库中,还从数据库中检索并将其加载到listview。一切正常,但listview上显示的图像质量非常差,尽管原始图像质量很好 SearchViewBinder.java从SQLiteDatabase检索到的图像加载到listview android时质量非常差,android,Android,我将图像转换为字节并保存到数据库中,还从数据库中检索并将其加载到listview。一切正常,但listview上显示的图像质量非常差,尽管原始图像质量很好 SearchViewBinder.java public class SearchViewBinder implements SimpleCursorAdapter.ViewBinder, ViewBinder{ public boolean setViewValue(View view, Cursor cursor, int co
public class SearchViewBinder implements SimpleCursorAdapter.ViewBinder, ViewBinder{
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
if(view instanceof ImageView)
{
Options options = new BitmapFactory.Options();
options.inScaled = false;
ImageView iv=(ImageView) view;
byte[] img=cursor.getBlob(columnIndex);
iv.setImageBitmap(BitmapFactory.decodeByteArray(img, 0, img.length));
return true;
}
return false;
}
}
list_row.xml
<LinearLayout
android:id="@+id/list_row"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dip"
android:background="@drawable/image_bg"
android:padding="3dip" >
<!-- THUMBAIL IMAGE -->
<ImageView
android:id="@+id/list_image"
android:layout_width="85dip"
android:layout_height="80dip"
android:scaleType="fitXY"
android:shadowColor="#585858"
android:shadowDx="0.0"
android:shadowDy="0.0"
android:shadowRadius="20"
android:src="@drawable/karthik" />
</LinearLayout>
图像转换为位图
public static Bitmap getContactImage(Context context,ContentResolver cr,String id){
Uri contactUri=ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, Long.parseLong(id));
InputStream inputStream=ContactsContract.Contacts.openContactPhotoInputStream(cr, contactUri);
if (inputStream==null) {
return BitmapFactory.decodeResource(context.getResources(),R.drawable.no_photo_placeholder);
}
return BitmapFactory.decodeStream(inputStream);
}
位图转换为字节数组
public static byte[] convertImageToByte(Bitmap bitmap){
ByteArrayOutputStream outputStream=new ByteArrayOutputStream();
bitmap.compress(CompressFormat.JPEG,0,outputStream);
return outputStream.toByteArray();
}
您正在压缩质量参数设置为0的图像。试试100吧。如果将图像另存为.png格式,则质量参数无关紧要,但使用JPEG压缩则无关紧要
public static byte[] convertImageToByte(Bitmap bitmap){
ByteArrayOutputStream outputStream=new ByteArrayOutputStream();
bitmap.compress(CompressFormat.JPEG,100,outputStream);
return outputStream.toByteArray();
}图像保存在哪里?发布代码,这样我们就可以知道你是否在保存时压缩了太多。@karthik你在这里做什么?不要这样说。如果您的问题有问题,请等待回复,否则请删除此问题。@Tim Kranen-----请查看我的更新code@Neil不要让人泄气。如果你认为你能以更好的方式引导他,那就这么做。这里不需要使用俚语。@Piyus Gupta-----别误会我…我刚刚回复了@NeilIt,如果选项设置为100,或CompressFormat.PNG而不考虑选项,则会给出相同的结果。您是否100%肯定原始图像(通过.getBlob()获得)是高质量的图像?@karthik好奇,这仅仅是一个参数吗?我尝试用另一个高质量的联系人图像更改联系人图像,然后成功了…我想检索两个图像我应该如何更改SearchViewBinder.java,因为它只处理一个ImageView我想你需要问一个单独的问题,我以前从未使用过这样的模式(SearchViewBinder)。
public static byte[] convertImageToByte(Bitmap bitmap){
ByteArrayOutputStream outputStream=new ByteArrayOutputStream();
bitmap.compress(CompressFormat.JPEG,100,outputStream);
return outputStream.toByteArray();