2016-03-22 44 views
0

内のギャラリーに保存しないようにする方法:スクリーンショットを撮ると私はスクリーンショットのためのコードの下に使用し、アンドロイド

public class startActivity{ 
    Bitmap layoutBitmap = Bitmap.createBitmap(mReLayout.getWidth(), mReLayout.getHeight(), Bitmap.Config.ARGB_4444); 
    Canvas canvas = new Canvas(layoutBitmap); 
    mReLayout.draw(canvas); 
    Uri uri = getImageUri(getApplicationContext(), layoutBitmap); 
    Intent mIntent = new Intent(CategoryActivity.this, MainActivity.class); 
    mIntent.putExtra(Constant.BYTE_IMAGE, uri.toString()); 
    startActivity(mIntent); 
} 

MainActivity.class

private void setUpImageBitmap() { 
    Uri uri = Uri.parse(getIntent().getExtras().getString(Constant.BYTE_IMAGE)); 
    String selectedImagePath = getPath(uri); 
    mImageCube.setImageBitmap(Utils.decodeSampledBitmapFromResource(selectedImagePath, 200, 200)); 

} 

public String getPath(Uri uri) { 
    Cursor cursor = getContentResolver().query(uri, null, null, null, null); 
    cursor.moveToFirst(); 
    int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA); 
    return cursor.getString(idx); 
} 

クラスUtilsの

public static Bitmap decodeSampledBitmapFromResource(String resId, 
                int reqWidth, int reqHeight) { 

    // First decode with inJustDecodeBounds=true to check dimensions 
    final BitmapFactory.Options options = new BitmapFactory.Options(); 
    options.inJustDecodeBounds = true; 
    BitmapFactory.decodeFile(resId, options); 

    // Calculate inSampleSize 
    options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); 

    // Decode bitmap with inSampleSize set 
    options.inJustDecodeBounds = false; 
    return BitmapFactory.decodeFile(resId, options); 
} 

public static int calculateInSampleSize(
     BitmapFactory.Options options, int reqWidth, int reqHeight) { 
// Raw height and width of image 
    final int height = options.outHeight; 
    final int width = options.outWidth; 
    int inSampleSize = 2; 

    if (height > reqHeight || width > reqWidth) { 
     if (width > height) { 
      inSampleSize = Math.round((float) height/(float) reqHeight); 
     } else { 
      inSampleSize = Math.round((float) width/(float) reqWidth); 
     } 
    } 
    return inSampleSize; 
} 

ギャラリーに保存せずにスクリーンショットを撮るにはどうすればよいですか?

+0

どのような質問がありますか?スクリーンショットを撮る必要がありますが、ストレージに保存しないでください。またはスクリーンショットを撮るがギャラリーには表示されない、またはスクリーンショットを撮るがギャラリーには入っていない?私に教えてください –

+0

私はgaleryにそれを保存したくありません。助けて! –

+0

これはギャラリーに表示されないことを意味しますか?右? –

答えて

0

ここでは、アンドロイドコントロールのスクリーンショットを取る方法のコードは、ImageViewまたはレイアウトを意味します。 ImageViewのコードの下にあります。

ImageView iv = (ImageView) findViewById(R.id.imageView1); 
    View v1 = getWindow().getDecorView().getRootView(); 
    // View v1 = iv.getRootView(); //even this works 
    // View v1 = findViewById(android.R.id.content); //this works too 
    // but gives only content 
    v1.setDrawingCacheEnabled(true); 
    myBitmap = v1.getDrawingCache(); 
    saveBitmap(myBitmap); 

saveBitmap(myBitmap);

 public void saveBitmap(Bitmap bitmap) { 
    String filePath = Environment.getExternalStorageDirectory() 
    + File.separator + "Pictures/screenshot.png"; 
    String nomedia = Environment.getExternalStorageDirectory() 
    + File.separator + "Pictures/.nomedia"; 
    File nomediaFile= new File(nomedia); 
    if(!nomediaFile.exists()){ 
    nomediaFile.createNewFile(); 
     } 
    File imagePath = new File(filePath); 
    FileOutputStream fos; 
    try { 
      fos = new FileOutputStream(imagePath); 
      bitmap.compress(CompressFormat.PNG, 100, fos); 
      fos.flush(); 
      fos.close(); 
      sendMail(filePath); 
    } catch (FileNotFoundException e) { 
      Log.e("GREC", e.getMessage(), e); 
    } catch (IOException e) { 
      Log.e("GREC", e.getMessage(), e); 
    } 
    } 

今、あなたは、あなたはスクリーンショット保存のフォルダに.nomediaファイルをceateする必要がギャラリー内の任意の画像を表示したくありません。そのためのコードを見てください。

 String nomedia = Environment.getExternalStorageDirectory() 
    + File.separator + "Pictures/.nomedia"; 
    File nomediaFile= new File(nomedia); 
    if(!nomediaFile.exists()){ 
    nomediaFile.createNewFile(); 
     } 

上記のコードはすでにsaveBitmap()メソッドで実装されています。私はあなたのためにこれを手伝ってくれると思います...

この画像を共有し、画像のパスを取得し、下のコードで共有します。

public void shareImage(String path) { 
       Uri myUri = Uri.parse("file://" + path); 
       Intent shareIntent = new Intent(); 
       shareIntent.setAction(Intent.ACTION_SEND); 
       shareIntent.putExtra(Intent.EXTRA_TEXT, "Hello"); 
       shareIntent.putExtra(Intent.EXTRA_STREAM, myUri); 
       shareIntent.setType("image/jpeg"); 
       shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
       startActivity(Intent.createChooser(shareIntent, "send")); 
       } 
+0

大変ありがとうございます! –

+0

ImageViewで画像を表示する方法 –

+0

あなたのパスから画像を取得し、Uriでパスを変換するだけです。ウリはイメージビューに入った。 –

0

イメージファイルはどこかに保存する必要があります。あなたの実際の質問は、ギャラリーアプリケーションから画像ファイルを隠す方法です。あなたのギャラリーアプリからそれらを隠すために

これを行う2つの方法があります(URIによって与えられた)あなたがあなたのイメージを保存するフォルダの中にあなたを

1. .nomediaファイルを作成します。名前が.nomediaのファイルを作成する必要があります。ドットと

2.プレフィックスフォルダ:

あなたはドットでフォルダ自体の名前を変更することができます。例:.images

関連する問題