8

スナップショットを撮ってサムネイルを作成し、この画像を共有しています。しかし、サムネイルはすべて黒く表示されます。次のコードを使用しました

Bitmap bitmap;
View v1 = v.getRootView();
v1.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v1.getDrawingCache());
String url = Images.Media.insertImage(
mContext.getContentResolver(), bitmap, "title", null);

このコードの何が問題なのか、誰か教えてください。

編集

private View.OnClickListener shareListener = new View.OnClickListener() {
        public void onClick(View v) {
            Bitmap bitmap;
            View v1 = v.getRootView();
            v1.setDrawingCacheEnabled(true);
            bitmap = Bitmap.createBitmap(v1.getDrawingCache());
            String url = Images.Media.insertImage(
                    mContext.getContentResolver(), bitmap, "title", null);
            v1.setDrawingCacheEnabled(false);
            Activity activity = (Activity) getContext();
            Intent share = new Intent(Intent.ACTION_SEND);
            share.setType("image/jpeg");
            share.putExtra(Intent.EXTRA_STREAM, Uri.parse(url));
            activity.startActivity(Intent.createChooser(share,
                    "Share"));

        }

    };

黒画像 ここに画像の説明を入力

4

5 に答える 5

0

このコードを適用してみてください:

private File takeScreenshot(boolean showToast) {
    View v = getWindow().getDecorView();

    v.setDrawingCacheEnabled(true);
    Bitmap cachedBitmap = v.getDrawingCache();
    Bitmap copyBitmap = cachedBitmap.copy(Bitmap.Config.RGB_565, true);
    FileOutputStream output = null;
    File file = null;
    try {
        File path = Places.getScreenshotFolder();
        Calendar cal = Calendar.getInstance();

        file = new File(path,

        cal.get(Calendar.YEAR) + "_" + (1 + cal.get(Calendar.MONTH)) + "_"
                + cal.get(Calendar.DAY_OF_MONTH) + "_"
                + cal.get(Calendar.HOUR_OF_DAY) + "_"
                + cal.get(Calendar.MINUTE) + "_" + cal.get(Calendar.SECOND)
                + ".png");
        output = new FileOutputStream(file);
        copyBitmap.compress(CompressFormat.PNG, 100, output);
    } catch (FileNotFoundException e) {
        file = null;
        e.printStackTrace();
    } finally {
        if (output != null) {
            try {
                output.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

    if (file != null) {
        if (showToast)
            Toast.makeText(getApplicationContext(),
                    "Saved " + file.getAbsolutePath(),
                    Toast.LENGTH_LONG).show();
        // sending a broadcast to the media scanner so it will scan the new
        // screenshot.
        Intent requestScan = new Intent(
                Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
        requestScan.setData(Uri.fromFile(file));
        sendBroadcast(requestScan);

        return file;
    } else {
        return null;
    }
}

これは私にとって完璧に機能します。これがあなたを助けることを願っています。

于 2013-05-31T07:22:27.343 に答える
0

これは、あなたの地域が安全であるとマークされているために発生する可能性があります。アイコンが表示されている間、コンテンツを表示するビューは安全であるため黒く表示されます。

セキュア サーフェスまたは保護されたバッファのコンテンツではなく、画面に空白の領域が表示される場合があります。

http://developer.android.com/reference/android/view/Display.html#FLAG_SECURE

于 2013-05-31T07:42:13.800 に答える