我试图将来自Drawable的图片附加到电子邮件中(从我的应用程序到Gmail应用程序)
我已经尝试了下面的代码:
Intent emailintent2 = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
emailintent2.setType("image/*");
emailintent2.putExtra(Intent.EXTRA_EMAIL, emailaddress2);
emailintent2.putExtra(Intent.EXTRA_SUBJECT, CorAsunto);
emailintent2.putExtra(Intent.EXTRA_TEXT, message2);
ArrayList<Uri> uris = new ArrayList<Uri>();
uris.add(Uri.parse("android.resource://" + getPackageName() + "/" + R.drawable.image1));
uris.add(Uri.parse("android.resource://" + getPackageName() + "/" + R.drawable.image2));
emailintent2.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivity(emailintent2);但当我将图片附加到电子邮件中时,我得到的附件没有扩展名".png“,这是一个大问题。
所以我认为在尝试将这些可绘制的图像转换为位图时,我也认为ArrayList必须是位图。我想我会得到的图像在附件中定义了图像。
如果可能的话,有人能告诉我怎么做吗?转换为位图,添加到Arraylist并附加图像。
如果我说的都是错的,有人能给我一个解决方案吗?我需要将图像从Drawable附加到扩展名为(.png)的电子邮件。
发布于 2015-05-13 14:35:06
有3种方式执行转换:
resource image设置ImageViewimageView.setImageResource(R.drawable.icon);
然后从imageView获取位图
Bitmap bitmap =通过Resource ID直接((BitmapDrawable)image.getDrawable()).getBitmap();
R.drawable.profile_circle);
ImageView上绘制图像,然后将其转换为Bitmap (也适用于svg/VectorDrawable )位图imgView = ( ImageView ) findViewById(R.id.ImageView);位图z.setDrawingCacheEnabled(true);位图位图= Bitmap.createBitmap(v.getDrawingCache());
发布于 2013-03-07 03:03:38
Drawable myDrawable = getResources().getDrawable(R.drawable.anImage);
Bitmap anImage = ((BitmapDrawable) myDrawable).getBitmap();也可以使用<bitmap>元素在XML文件中定义它。
发布于 2013-03-07 03:12:58
这是一段代码,只需查看它:
Bitmap Icon = BitmapFactory.decodeResource(getResources(), R.drawable.large_icon);https://stackoverflow.com/questions/15255611
复制相似问题