public class SaveImageAsync extends AsyncTask<Integer, Void, Void> {
@Override
protected Void doInBackground(Integer... params) {
try {
InputStream in;
BufferedInputStream buf;
int position = params[0];
if (URLUtil.isNetworkUrl(use image here)) {
in = new URL(use image here
).openStream();
buf = new BufferedInputStream(in);
Bitmap _bitmapPreScale = BitmapFactory.decodeStream(buf);
int oldWidth = _bitmapPreScale.getWidth();
int oldHeight = _bitmapPreScale.getHeight();
int newWidth = 2592;
int newHeight = 1936;
float scaleWidth = ((float) newWidth)/oldWidth;
float scaleHeight = ((float) newHeight)/oldHeight;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
Bitmap _bitmapScaled = Bitmap.createBitmap(_bitmapPreScale, 0, 0, oldWidth, oldHeight, matrix, true);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
_bitmapScaled.compress(Bitmap.CompressFormat.JPEG, 40, bytes);
File directory = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM),"wave");
directory.mkdirs();
directory.mkdir();
File f = new File(directory, "writeurnamefolder_Gallery" + System.currentTimeMillis() + ".jpg");
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
fo.close();
} else if (URLUtil.isFileUrl(use here original image)) {
MediaStore.Images.Media.insertImage(getContentResolver(), Uri.parse(get your image here.getPath(), "writeurnamefolder_Gallery" + System.currentTimeMillis(), "Gallery Image :");
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
これはクラス 'cameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT、picUri);で使用します。 –
あなたのコードをよく表示します。 – greenapps
'カメラは画像をもう保存しません。カメラは画像を保存しません。カメラアプリだけがそうすることができます。あなたは1つを使用していますか?あなたはまだあなたのデバイス上のカメラアプリで通常の方法で写真を撮ることができますか? – greenapps