Verwenden Sie den folgenden Code Ansicht blättern Inhalt Bild zu konvertieren.
//step :1
int height;
int width;
ScrollViewHelper iv;
//step :2
iv = (ScrollViewHelper) findViewById(R.id.scrollViewHelper);
iv.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
@Override
public void onScrollChanged() {
height = iv.getChildAt(0).getHeight();
width = iv.getChildAt(0).getWidth();
}
});
//step :3
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas ccc = new Canvas(bitmap);
iv.getChildAt(0).draw(ccc);
SaveImage(bitmap);
//step :4
private void SaveImage(Bitmap finalBitmap) {
String root = Environment.getExternalStorageDirectory().toString();
//File myDir = new File("/storage/emulated/0/DCIM");
File myDir = new File(root+ File.separator + "Vengat.jpg");
myDir.mkdirs();
Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
String fname = "Image"+ n +".jpg";
File file = new File(myDir, fname);
if (file.exists())
file.delete();
try {
FileOutputStream out = new FileOutputStream(file);
finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.flush();
out.close();
File filePath =new File(file.toString()); //optional //internal storage
// File filePath =new File(Environment.getExternalStorageDirectory().toString()); //optional //internal storage
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Open it in Google Play Store to Download the Application");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(filePath)); //optional//use this when you want to send an image
shareIntent.setType("*/*");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "send"));
}
catch (FileNotFoundException e) {
e.printStackTrace();
Log.i("", "******* File not found. Did you"
+ " add a WRITE_EXTERNAL_STORAGE permission to the manifest?");
}
catch (Exception e) {
e.printStackTrace();
}
}
//////////////////////
<ScrollViewHelper
android:id="@+id/scrollViewHelper"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ScrollView>
</ScrollViewHelper>
////////////// // ScrollViewHelper: -
public class ScrollViewHelper erstreckt Scroll {
private OnScrollViewListener mOnScrollViewListener;
public ScrollViewHelper(Context context) {
super(context);
}
public ScrollViewHelper(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ScrollViewHelper(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public interface OnScrollViewListener {
void onScrollChanged(ScrollViewHelper v, int l, int t, int oldl, int oldt);
}
public void setOnScrollViewListener(OnScrollViewListener l) {
this.mOnScrollViewListener = l;
}
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
mOnScrollViewListener.onScrollChanged(this, l, t, oldl, oldt);
super.onScrollChanged(l, t, oldl, oldt);
}
}
Was ist eigentlich der Zweck ist? Die Sache, die du versuchst zu tun, ist ziemlich ungewöhnlich. –
Ich muss mein Bild in PDF-Dokument für meine Anwendung konvertieren. –