View Full Version : گرفتن اسکرین شات در برنامه
  
hrostadi
چهارشنبه 08 مهر 1394, 17:13 عصر
سلام
من یه جای برنامم نیاز دارم اسکرین شات بگیرم از صفحه ی برنامه. ینی بهتره بگم از صفحه گوشی چون میخوام استتوس بار هم توی اسکرین شات پیدا باشه. چنتا راه حل رو پیدا کردم ولی همشون فقط از صفحه برنامه عکس میگرفتن و استتوس بار پیدا نبود. کسی راه حلی میدونه؟؟
یه چیزی هم پیدا کردم android screenshot library:
https://code.google.com/p/android-screenshot-library/
ولی نحوه استفاده ازش رو نفهمیدم چطوریه.
کسی هست بتونه کمک کنه؟
ممنون از همه
slr560
چهارشنبه 08 مهر 1394, 20:38 عصر
ابتدا پرمیشن
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
private void takeScreenshot() {    Date now = new Date();
    android.text.format.DateFormat.format("yyyy-MM-dd_hh:mm:ss", now);
    try {
        // image naming and path  to include sd card  appending name you choose for file
        String mPath = Environment.getExternalStorageDirectory().toString () + "/" + now + ".jpg";
        // create bitmap screen capture
        View v1 = getWindow().getDecorView().getRootView();
        v1.setDrawingCacheEnabled(true);
        Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
        v1.setDrawingCacheEnabled(false);
        File imageFile = new File(mPath);
        FileOutputStream outputStream = new FileOutputStream(imageFile);
        int quality = 100;
        bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream);
        outputStream.flush();
        outputStream.close();
        openScreenshot(imageFile);
    } catch (Throwable e) {
        // Several error may come out with file handling or OOM
        e.printStackTrace();
    }
}
نمایش عکس گرفته شده
private void openScreenshot(File imageFile) {    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    Uri uri = Uri.fromFile(imageFile);
    intent.setDataAndType(uri, "image/*");
    startActivity(intent);
}
hrostadi
جمعه 10 مهر 1394, 10:10 صبح
ابتدا پرمیشن
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
private void takeScreenshot() {    Date now = new Date();
    android.text.format.DateFormat.format("yyyy-MM-dd_hh:mm:ss", now);
    try {
        // image naming and path  to include sd card  appending name you choose for file
        String mPath = Environment.getExternalStorageDirectory().toString () + "/" + now + ".jpg";
        // create bitmap screen capture
        View v1 = getWindow().getDecorView().getRootView();
        v1.setDrawingCacheEnabled(true);
        Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
        v1.setDrawingCacheEnabled(false);
        File imageFile = new File(mPath);
        FileOutputStream outputStream = new FileOutputStream(imageFile);
        int quality = 100;
        bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream);
        outputStream.flush();
        outputStream.close();
        openScreenshot(imageFile);
    } catch (Throwable e) {
        // Several error may come out with file handling or OOM
        e.printStackTrace();
    }
}
نمایش عکس گرفته شده
private void openScreenshot(File imageFile) {    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    Uri uri = Uri.fromFile(imageFile);
    intent.setDataAndType(uri, "image/*");
    startActivity(intent);
}
ممنون ولی این کد هم استتوس بار رو نشون نمیده
 
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.