下载Imageview文本

时间:2017-10-21 16:53:25

标签: android

我有一个ImageView和一些用户输入作为文本。我想添加用户输入ImageView的输入并下载它。但是,当我尝试时,它只会下载纯ImageView

这是xml文件:

<RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/relLayout1"
            android:id="@+id/relLayout2"
            android:background="@drawable/grey_border_bottom">

            <ImageView
                android:layout_width="300dp"
                android:layout_height="300dp"
                android:id="@+id/imageSee"
                android:src="@drawable/pink_bg"
                android:scaleType="centerCrop"
                android:layout_centerVertical="true"
                android:layout_centerHorizontal="true"
                android:layout_marginLeft="20dp"
                android:layout_marginBottom="40dp" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/textOnImage"
                android:text="hsjsdjhf"
                android:gravity="center"
                android:layout_centerVertical="true"
                android:textSize="20dp"
                android:layout_alignTop="@id/imageShare"
                android:layout_alignBottom="@id/imageShare"
                android:layout_alignLeft="@id/imageShare"
                android:layout_alignRight="@id/imageShare" />


        </RelativeLayout>

使用用户输入成功更新了Imageview,这是一个完全正常的功能:

 private void downloadImage()
{
    BitmapDrawable drawable = (BitmapDrawable) mImage.getDrawable();
    Bitmap bitmap = drawable.getBitmap();

    File path = Environment.getExternalStorageDirectory();  // storage/emulated/0

    File dir = new File(path + "/savehere/");
    if(!dir.exists())
    {
        dir.mkdirs();
    }
    else
    {
        Toast.makeText(mContext, "Directory already exists", Toast.LENGTH_SHORT).show();
    }


    File file = new File(dir,"pinkWithText.png");

    OutputStream out = null;

    try
    {
        out = new FileOutputStream(file);
        bitmap.compress(Bitmap.CompressFormat.PNG,100,out);
        out.flush();
        out.close();

    }
    catch (FileNotFoundException e)
    {
        e.printStackTrace();
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
}

0 个答案:

没有答案