similar type of questions has been asked several times, but I am still having a tough time to understand where the image is saved. I am using the accepted solution of this SO question.
I have a cardview
that I want to convert to an image and share it(that's a different issue).
My cardview is:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
......
android.support.v7.widget.CardView
android:id="@+id/cv_abtme"
android:layout_width="368sp"
android:layout_height="273dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="101dp"
android:background="@color/colorPrimaryLight"
app:cardBackgroundColor="@color/about_instagram_color"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/imageView4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
app:srcCompat="@mipmap/ic_launcher" />
....
</android.support.v7.widget.CardView>
I am trying to convert it as:
public class AboutMeActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about_me);
ImageButton cvbutton= findViewById(R.id.imageButton_abtme);
cvbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
getBitmapFromView(view);
Snackbar.make(getCurrentFocus(),"Image Captured", Snackbar.LENGTH_LONG).show();
}
});
}
public static Bitmap getBitmapFromView(View view) {
Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(),Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(returnedBitmap);
Drawable bgDrawable =view.getBackground();
if (bgDrawable!=null)
bgDrawable.draw(canvas);
else
canvas.drawColor(Color.WHITE);
view.draw(canvas);
return returnedBitmap;
}
}
But I have no idea how it's working, as I can't see any image produced, but obviously no error.
So, the question is:
- What is the path the image created?
- Do I need some permission to save and access the jpg?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…