0

I have an ImageView and some user input as text. I want to add that input the user enters onto the ImageView and download it. However, when I try, it only downloads the pure ImageView.

This is the xml file:

<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 successfully updated with user input, and this is the function, which works completely fine:

 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();
    }
}
Simon
  • 2,643
  • 3
  • 40
  • 61
Coni Sayns
  • 45
  • 6
  • You are taking only the drawable from ImageView. You have to do it something like taking a screenshot. Refer this post: https://stackoverflow.com/questions/2661536/how-to-programmatically-take-a-screenshot-in-android – Srijith Oct 21 '17 at 17:00
  • Does it literally take the screenshot, or just the imageview or something? – Coni Sayns Oct 21 '17 at 17:04
  • Since whatever drawn on screen can be accessed as bitmap, this is what taking screenshot means literally. – Srijith Oct 21 '17 at 17:08
  • `I want to add that input the user enters onto the ImageView and download it. However, when I try, it only downloads the pure ImageView.` ??? I did not read further as i do not undersstand a word of this. – greenapps Oct 21 '17 at 19:26
  • I could suggest you some English learning websites since it is extremely weird you don't understand my question even after seeing my post yesterday. One would expect at least making a connection between them. Btw, I solved the problem, no need to read further. – Coni Sayns Oct 21 '17 at 20:03

0 Answers0