実行時に一番上の画像の不透明度を変更して2つの画像を重ね合わせた後、その2つの画像を合成します画像)を開き、Galleryに保存します。アンドロイドスタジオでこれを達成する方法?画像の不透明度をプログラムで変更してギャラリーに保存する方法
0
A
答えて
0
画像がフルスクリーンの場合は、独自のスクリーンショットを作成するだけです。
public static Bitmap takeScreenshotOfView(Activity context, Bitmap.CompressFormat compressFormat){
Bitmap screenshot = null;
try {
// create bitmap screen capture
View v1 = context.getWindow().getDecorView().getRootView();
v1.setDrawingCacheEnabled(true);
screenshot = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
File imageFile = new File(context.getFilesDir() + File.separator + "A35_temp" + File.separator + "screenshot_temp");
FileOutputStream outputStream = new FileOutputStream(imageFile);
int quality = 100;
screenshot.compress(compressFormat, quality, outputStream);
outputStream.flush();
outputStream.close();
} catch (Throwable e) {
// Several error may come out with file handling or OOM
e.printStackTrace();
}
return screenshot;
}
そして、ちょうど同じようにそれを使用します:
Bitmap screenshot = ImageHelper.takeScreenshotOfView(this, Bitmap.CompressFormat.JPEG);
したいか、私はこのようImageHelperをという名前のクラスに入れて簡単なコードを使用することができればあなたのためにこれを行います偉大なライブラリがたくさんあります
ImageViewの領域をキャプチャするだけであれば、ビューで取得するか、両方のイメージビューの親を取得してそれらを含めることができます。フルスクリーンを指定することもできますが、imageViewの開始点と終了点から開始することができます。個々の領域のスクリーンショットを管理するために書いたサンプルコードです。
private void convertCardToBitmap(boolean sendOnComplete){
if(!mIsForStore) {
Toast.makeText(this, getString(R.string.downloading_to_gallery), Toast.LENGTH_LONG).show();
}
CardView cardView = (CardView)findViewById(R.id.my_image_view_id);
cardView.setDrawingCacheEnabled(true);
cardView.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
//cardView.measure((int)height, (int)width);
cardView.layout(0, 0, cardView.getMeasuredWidth(), cardView.getMeasuredHeight());
//cardView.layout(0, 0, (int)width, (int)height);
cardView.buildDrawingCache(true);
Bitmap bitmap = Bitmap.createBitmap(cardView.getDrawingCache());
saveBitmapToGallery(bitmap, sendOnComplete);
}
private void saveBitmapToGallery(Bitmap cardToSave, boolean sendFileWhenSaved){
OutputStream output;
// Find the SD Card path
File filepath = Environment.getExternalStorageDirectory();
// Create a new folder in SD Card
File dir = new File(filepath.getAbsolutePath() + "/MyAppPathDir/");
dir.mkdirs();
String imageName = mSelectedPerson.getFirstName() + "_" + mSelectedPerson.getLastName() + "_" + FileNameHelper.getNowTimeStamp();
// Create a name for the saved image
File file = new File(dir, imageName + ".jpg");
try {
int count = 1;
//if file exists add 1 on the end and loop until finding a name that doesn't exist.
while(file.exists()){
file = new File(dir, imageName + count + ".jpg");
count++;
}
output = new FileOutputStream(file);
// Compress into png format image from 0% - 100%
cardToSave.compress(Bitmap.CompressFormat.JPEG, 100, output);
output.flush();
output.close();
addImageToGallery(file.getAbsolutePath());
if(sendFileWhenSaved){
Intent intent = getIntent();
intent.putExtra(Globals.INTENT_KEYS.KEY_FILE_TO_SHARE, file.getAbsolutePath());
intent.putExtra(Globals.INTENT_KEYS.KEY_SELECTED_IMAGE, mSelectedCardModel);
setResult(RESULT_OK, intent);
finish();
} else if (mIsForStore) {
uploadImageToS3(file.getAbsolutePath());
} else{
Toast.makeText(this, getString(R.string.saved_to_gallery), Toast.LENGTH_LONG).show();
finish();
}
} catch (Exception e) {
Toast.makeText(this, getString(R.string.error_failed_save_to_gallery) + e.getMessage(), Toast.LENGTH_LONG).show();
}
}
private void uploadImageToS3(String filePath){
final File newImageFile = new File(filePath);
showProgressDialog(TAG, getString(R.string.loading_please_wait));
//For auth route
BasicAWSCredentials credentials = new BasicAWSCredentials(CognitoManager.getS3ClientID(), CognitoManager.getS3ClientSecret());
AmazonS3Client s3 = new AmazonS3Client(credentials);
TransferUtility transferUtility = new TransferUtility(s3, this);
TransferObserver observer = transferUtility.upload(CognitoManager.getS3BucketName(), newImageFile.getName(), newImageFile);
observer.setTransferListener(new TransferListener() {
@Override
public void onStateChanged(int id, TransferState state) {
if(state.compareTo(TransferState.COMPLETED) == 0){
String imgURLOfUploadComplete = "https://s3.amazonaws.com/" + CognitoManager.getS3BucketName() + "/" + newImageFile.getName();
hideProgressDialog(TAG);
Intent intent = new Intent();
intent.putExtra(Globals.INTENT_KEYS.KEY_IMAGE_URL, imgURLOfUploadComplete);
setResult(Activity.RESULT_OK, intent);
if(newImageFile.exists()){
newImageFile.delete();
}
finish();
}
}
@Override
public void onProgressChanged(int id, long bytesCurrent, long bytesTotal) {
if(bytesTotal != 0) {
//For viewing progress
int percentage = (int) (bytesCurrent/bytesTotal * 100);
}
}
@Override
public void onError(int id, Exception ex) {
A35Log.e(TAG, getString(R.string.error_uploading_s3_part1) + id + getString(R.string.error_uploading_s3_part2) + ex.getMessage());
hideProgressDialog(TAG);
showDialogMessage(getString(error), getString(R.string.error_failed_create_image_alert_id) + error);
}
});
}
public void addImageToGallery(final String filePath) {
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.DATE_TAKEN, System.currentTimeMillis());
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
values.put(MediaStore.MediaColumns.DATA, filePath);
getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
}
ホープが役に立ちます:)。 setDrawCacheEnabledを起動すると、画面上で奇妙な動作が発生し、場合によっては制約を削除するように見えるため、再描画が必要になることがありますが、警告が表示されます。この理由から、私はしばしば、イメージに変換しているコンテンツを含む新しい空白の画面を開き、作業を終了して閉じます。
これはあなたのためにどのように動作するかを見て、そこからどこに行くのかを決めます。私が試したほとんどの図書館も同じ問題を抱えていたので、私は自分自身で書いたのです。
関連する問題
- 1. Androidギャラリーで画像の不透明度を変更する方法
- 2. png画像の不透明度/アルファベット/透明度を変更する
- 3. CSSで背景画像の不透明度を変更する
- 4. シンプルな画像ギャラリー - jquery経由で画像の不透明度を変更しますか?
- 5. 変化画像の不透明度と
- 6. 背景画像の不透明度を変更する
- 7. 画像の不透明度を変更する
- 8. 背景画像の不透明度を変更する
- 9. JavaScriptキャンバス - 画像の不透明度を変更する
- 10. div内の画像の不透明度を変更する一方、不透明度を変更せずにその下のテキストの色を変更します
- 11. ImageViewの不透明画像上の透明度画像
- 12. テキストの不透明度を変更せずにフォームウィンドウの不透明度を変更する方法
- 13. 画像はまだ不透明度値の変化後の半透明の不透明度を示し
- 14. ホバー変更不透明度
- 15. PHPは画像の透明度を保存します
- 16. 背景画像angacity2の不透明度
- 17. コンテンツの不透明度を変更せずに背景の不透明度を変更する
- 18. 不透明度を変更すると画像の位置が壊れます
- 19. 不透明度の変更とサークルオーバーレイを含む画像ですか?
- 20. jQueryで画像の不透明度を変更できません
- 21. JavaFX LineChart - 透明な画像を保存
- 22. jQueryの不透明度を持つ画像上の不透明度をオーバーライドするには
- 23. JavaのcreateImageで画像の不透明度を調整する
- 24. LinearGradientBrushの不透明度をwinformsの画像に適用する
- 25. フィルタ:プログラムID: プログラムID:DXImageTransform.Microsoft.Alpha(スタイル= 1、不透明度= 80 ) 不透明DXImageTransform.Microsoft.Alpha(スタイル= 1、不透明度= 80)
- 26. ギャラリーに画像を保存
- 27. ギャラリーに画像を保存
- 28. 画像の部分に不透明度を追加する(CSS)
- 29. 背景画像に透明度の不透明度を追加しようとしています
- 30. スクロールの不透明度の変更アイコン