Android 如何从imageview获取图像,以便通过位图发布

Android 如何从imageview获取图像,以便通过位图发布,android,bitmap,imageview,Android,Bitmap,Imageview,XML图像视图所在的位置 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vert

XML图像视图所在的位置

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="match_parent"
            android:layout_height="101dp"
            android:layout_marginTop="32dp"
            android:clickable="false"
            android:src="@drawable/image" />


</LinearLayout>
imageView = (ImageView) findViewById(R.id.imageView1);
我的问题

然后查看如何从图像视图获取图像的位图

Bitmap bitmapOrg = BitmapFactory.decodeResource(------?----------);

要从imageView获取可绘制的图像,请使用:

ImageVIew.getDrawable()
如果您想从可绘图设备获取inputstream,请使用以下命令:

BitmapDrawable bitmapDrawable = ((BitmapDrawable) drawable);
Bitmap bitmap = bitmapDrawable .getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] imageInByte = stream.toByteArray();
ByteArrayInputStream bis = new ByteArrayInputStream(imageInByte);

要从imageView获取可绘制的图像,请使用:

ImageVIew.getDrawable()
如果您想从可绘图设备获取inputstream,请使用以下命令:

BitmapDrawable bitmapDrawable = ((BitmapDrawable) drawable);
Bitmap bitmap = bitmapDrawable .getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] imageInByte = stream.toByteArray();
ByteArrayInputStream bis = new ByteArrayInputStream(imageInByte);

ImageView
中,首先将选项设置为
true
,然后将该图像转换为位图后保存到SD卡,然后共享该图像

请尝试以下操作:

          imageView = (ImageView) findViewById(R.id.imageView1);
          m_ivproimg.setDrawingCacheEnabled(true);
        Bitmap bitmap = m_ivproimg.getDrawingCache();

         //Save image into sdcard and given name randomly.   
        String root = Environment.getExternalStorageDirectory().toString();
        File newDir = new File(root + "/saved_images");
        newDir.mkdirs();
        Random gen = new Random();
        int n = 10000;
        n = gen.nextInt(n);
        String fotoname = "photo-" + n + ".jpg";
        File file = new File(newDir, fotoname);
        String s = file.getAbsolutePath();

        if (file.exists())
            file.delete();
        try {
            FileOutputStream out = new FileOutputStream(file);
            bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
            out.flush();
            out.close();
        } catch (Exception e) {

        }

ImageView
中,首先将选项设置为
true
,然后将该图像转换为位图后保存到SD卡,然后共享该图像

请尝试以下操作:

          imageView = (ImageView) findViewById(R.id.imageView1);
          m_ivproimg.setDrawingCacheEnabled(true);
        Bitmap bitmap = m_ivproimg.getDrawingCache();

         //Save image into sdcard and given name randomly.   
        String root = Environment.getExternalStorageDirectory().toString();
        File newDir = new File(root + "/saved_images");
        newDir.mkdirs();
        Random gen = new Random();
        int n = 10000;
        n = gen.nextInt(n);
        String fotoname = "photo-" + n + ".jpg";
        File file = new File(newDir, fotoname);
        String s = file.getAbsolutePath();

        if (file.exists())
            file.delete();
        try {
            FileOutputStream out = new FileOutputStream(file);
            bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
            out.flush();
            out.close();
        } catch (Exception e) {

        }
您可以这样使用:

Bitmap bm;

BitmapDrawable drawable = (BitmapDrawable) yourimageview.getDrawable();
bm = drawable.getBitmap();
您可以这样使用:

Bitmap bm;

BitmapDrawable drawable = (BitmapDrawable) yourimageview.getDrawable();
bm = drawable.getBitmap();

另外,您可以使用
setdrawingcacheenable
选项捕获imageView的图像并将其转换为位图,然后共享。@GrlsHu。。。。。。。。这是如何做到的。。。你能举个例子作为例子吗answer@Goldee:复习需要时间。我们不想浪费用户查看小编辑的宝贵时间。请只做实质性的编辑。@juergen d我认为这两个标记都与我添加的问题相关且重要。另外,您可以使用
setdrawingcacheenable
选项捕获imageView的图像并将其转换为位图,然后共享它。@GrlsHu。。。。。。。。这是如何做到的。。。你能举个例子作为例子吗answer@Goldee:复习需要时间。我们不想浪费用户查看小编辑的宝贵时间。请仅进行实质性编辑。@juergen d我认为这两个标记与我添加的问题相关且重要。[+1]用于共享信息谢谢亲爱的:)@smriti3[+1]用于共享信息谢谢亲爱的:)@smriti3