我有自定义列表视图,其中包含图像。现在我需要将该图像从一个活动提取到另一个活动。我使用了以下代码。它可以工作,但它从Listview获取相同的图像大小到另一个活动但我需要根据另一个活动修复它的大小。
ImageView imageview = (ImageView)itemView.findViewById(R.id.yourImageview);
Bitmap bitmap = ((BitmapDrawable)imageview.getDrawable()).getBitmap();
Intent intent = new Intent(activity.this, Nextactivity.class);
intent.putExtra("contentTwo", bitmap);
Bitmap receivedimage =(Bitmap) intent.getParcelableExtra("contentTwo");
imageview = (ImageView) findViewById(R.id.yourimageview);
imageview.setImageBitmap(receivedimage);
适配器代码:
public Screen(Activity a,
ArrayList<Data> DataList) {
// TODO Auto-generated constructor stub
activity = a;
bleepDraftDataList = draftDataList;
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader = new ImageLoader(activity.getApplicationContext());
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return bleepDraftDataList.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
private class ViewHolder {
private ImageView imageViewleft;
private ImageView imageViewlright;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
Data = DataList.get(position);
view = convertView;
final ViewHolder holder;
if (convertView == null) {
view = inflater.inflate(R.layout.something, null);
holder = new ViewHolder();
holder.imageViewleft = (ImageView) view
.findViewById(R.id.imageViewBleeplinecellleft);
holder.imageViewlright = (ImageView) view
.findViewById(R.id.imageViewBleeplinecellright);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
if (!Data.creator.image.equals("")) {
holder.imageViewleft.setTag(""
+ Data.creator.image);
imageLoader.DisplayImage("" + Data.creator.image,
activity, holder.imageViewleft);
}
if (!Data.preview.equals("")) {
holder.imageViewright.setTag(""
+ Data.preview);
imageLoader.DisplayImage("" + Data.preview, activity,
return view
}
}
答案 0 :(得分:1)
使用此功能并设置您希望图像的大小
receivedimage = Bitmap.createScaledBitmap(receivedimage , 260, 260, false);
// 260*260 Width* height change this to your requirement
您可以做的另一件事是,在 PutExtras 中获取图片路径
Bitmap receivedimage = BitmapFactory.decodeFile(imagepath);
imageview.setImageBitmap(receivedimage);