我正在处理一段代码,通过相机捕获图像,并从图库中选择图像并将其设置为列表视图中的imageview。
问题是......
实施例: 适用于-----相机,高清相机
不适用于------ Camera MX,Camera FX
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==CAMERA_REQUEST) {
if (resultCode==RESULT_OK) {
View view=getLayoutInflater().inflate(R.layout.list_row,null);
ImageView imgView=(ImageView)view.findViewById(R.id.list_image);
Bitmap bitmap=(Bitmap)data.getExtras().get("data");
byte bitObj[]=BirthdayCalculation.convertImageToByte(bitmap);
Log.v("Photo byte.......", bitObj.toString());
ContentValues values=new ContentValues();
values.put(BirthdayProvider.PHOTO, bitObj);
int count=getContentResolver().update(BirthdayProvider.CONTENT_URI, values, BirthdayProvider.NUMBER+"='"+SearchListActivity.longClickValue+"'", null);
if (count==1) {
finish();
imgView.setImageBitmap(Bitmap.createScaledBitmap(bitmap, 85, 80, false));
Log.v("Photo Updated Successfully", "Photo Updated Successfully");
Toast.makeText(getBaseContext(),"Updated Successfully",Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(getBaseContext(),"Updation Failed",Toast.LENGTH_SHORT).show();
}
}
}
else if (requestCode==GALLERY_REQUEST) {
if (resultCode==RESULT_OK) {
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
try {
BitmapFactory.decodeStream(getContentResolver().openInputStream(data.getData()), null, o);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
int width_tmp = o.outWidth, height_tmp = o.outHeight;
int scale = 1;
while(true) {
if(width_tmp / 2 < 200 || height_tmp / 2 < 200)
break;
width_tmp /= 2;
height_tmp /= 2;
scale *= 2;
}
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
Bitmap bitmap = null;
try {
bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(data.getData()), null, o2);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
byte bitObj[]=BirthdayCalculation.convertImageToByte(bitmap);
Log.v("bitObj[]", bitObj.toString());
ContentValues values=new ContentValues();
values.put(BirthdayProvider.PHOTO, bitObj);
int count=getContentResolver().update(BirthdayProvider.CONTENT_URI, values, BirthdayProvider.NUMBER+"='"+SearchListActivity.longClickValue+"'", null);
if (count==1) {
finish();
imgView.setImageBitmap(bitmap);
imgView.setScaleType(ScaleType.FIT_XY);
Log.v("Photo Updated Successfully", "Photo Updated Successfully");
Toast.makeText(getBaseContext(),"Updated Successfully",Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(getBaseContext(),"Updation Failed",Toast.LENGTH_SHORT).show();
}
}
}
}
list_row.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dip">
<!-- ListRow Left sied Thumbnail image -->
<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>
<TextView
android:id="@+id/sub_title_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="5dip"
android:gravity="right"
android:text="Facebook Friend"
android:textColor="#10bcc9"
android:textSize="12dip"
android:textStyle="bold" />
<!-- ARROW IMAGE -->
<!-- NAME -->
<!-- CONTACT NUMBER -->
<!-- BIRTHDATE -->
<TextView
android:id="@+id/title_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/list_row"
android:layout_toRightOf="@+id/list_row"
android:text="KARTHIK.KOLANJI"
android:textColor="#181818"
android:textSize="16dip"
android:textStyle="bold"
android:typeface="sans" />
<TextView
android:id="@+id/txtview_zodiac"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/TextView02"
android:layout_alignBottom="@+id/TextView02"
android:layout_toRightOf="@+id/TextView02"
android:text="Sagittarius"
android:textColor="#CC0000"
android:textSize="15sp"
android:textStyle="normal" />
<TextView
android:id="@+id/txtview_turns"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/list_image_arrow"
android:layout_below="@+id/list_image_arrow"
android:text="24"
android:textColor="#990000"
android:textSize="27sp"
android:textStyle="normal"
android:layout_marginTop="7dip"/>
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/txtview_type_of_reminder"
android:layout_alignBottom="@+id/txtview_type_of_reminder"
android:layout_alignLeft="@+id/TextView02"
android:text="Next birthday on : "
android:textColor="#181818"
android:textSize="15sp"
android:textStyle="normal"
android:layout_marginTop="3dip"/>
<TextView
android:id="@+id/txtview_next_bd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/TextView01"
android:layout_alignBottom="@+id/TextView01"
android:layout_toRightOf="@+id/TextView01"
android:text="Wednesday"
android:textColor="#CC0000"
android:textSize="15sp"
android:textStyle="bold"
android:layout_marginTop="2dip"/>
<TextView
android:id="@+id/sub_title_contact_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/title_name"
android:layout_below="@+id/title_name"
android:text="9594080469"
android:textColor="#181818"
android:textSize="15dip"
/>
<TextView
android:id="@+id/list_image_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/sub_title_category"
android:layout_alignTop="@+id/sub_title_contact_number"
android:text="turns"
android:textColor="#996600"
android:textSize="9sp"
android:textStyle="normal" />
<TextView
android:id="@+id/txtview_days_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/txtview_next_bd"
android:layout_alignBottom="@+id/txtview_next_bd"
android:layout_alignParentRight="true"
android:text="36"
android:textColor="#990000"
android:textSize="27sp"
android:textStyle="normal" />
<ImageView
android:id="@+id/ImageView02"
android:layout_width="15dip"
android:layout_height="20dip"
android:layout_alignLeft="@+id/list_row"
android:layout_below="@+id/list_row"
android:contentDescription="Zodiac icon"
android:scaleType="fitXY"
android:shadowColor="#8B4513"
android:shadowDx="0.0"
android:shadowDy="0.0"
android:shadowRadius="20"
android:src="@drawable/rings_icon"/>
<TextView
android:id="@+id/txtview_type_of_reminder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/ImageView02"
android:layout_toRightOf="@+id/ImageView02"
android:text="(Anniversary)"
android:textColor="#787878"
android:textSize="15sp"
android:textStyle="normal" />
<TextView
android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/txtview_type_of_reminder"
android:layout_alignLeft="@+id/sub_title_birthdate"
android:text="Zodiac : "
android:textColor="#181818"
android:textSize="15sp"
android:textStyle="normal" />
<TextView
android:id="@+id/sub_title_birthdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/sub_title_contact_number"
android:layout_centerVertical="true"
android:text="7th, April 1990"
android:textColor="#181818"
android:textSize="15dip" />
<TextView
android:id="@+id/TextView04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/txtview_turns"
android:layout_alignTop="@+id/ImageView01"
android:text=" days left"
android:textColor="#996600"
android:textSize="9sp"
android:textStyle="normal" />
<ImageView
android:id="@+id/ImageView01"
android:layout_width="20dip"
android:layout_height="20dip"
android:layout_above="@+id/txtview_next_bd"
android:layout_alignRight="@+id/txtview_next_bd"
android:layout_marginRight="16dp"
android:contentDescription="Zodiac icon"
android:scaleType="fitXY"
android:shadowColor="#8B4513"
android:shadowDx="0.0"
android:shadowDy="0.0"
android:shadowRadius="20" />
</RelativeLayout>