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();
}
}