18

保存する前にコードで画像のサイズを変更したいのですが、Google でそれについて何も見つかりません。私を手伝ってくれますか ?

これはコードです(Android docから):

private void galleryAddPic() {
    Intent mediaScanIntent = new Intent("android.intent.action.MEDIA_SCANNER_SCAN_FILE");
    File f = new File(mCurrentPhotoPath);

    picturePathForUpload = mCurrentPhotoPath;

    Uri contentUri = Uri.fromFile(f);
    mediaScanIntent.setData(contentUri);
    this.sendBroadcast(mediaScanIntent);
}

その後、サーバーにアップロードする必要があります。

どうもありがとう。

4

6 に答える 6

28

次のコードでビットマップ画像を保存できます

Bitmap photo = (Bitmap) "your Bitmap image";
photo = Bitmap.createScaledBitmap(photo, 100, 100, false);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
photo.compress(Bitmap.CompressFormat.JPEG, 40, bytes);

File f = new File(Environment.getExternalStorageDirectory()
        + File.separator + "Imagename.jpg");
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
fo.close();
于 2013-04-17T14:28:46.333 に答える
5

最初に画像をビットマップに変換してから、次のコードを使用します。

Bitmap yourBitmap;
Bitmap resized = Bitmap.createScaledBitmap(yourBitmap, newWidth, newHeight, true);
于 2013-04-17T12:40:04.767 に答える
1

これを参照してください 。ヘルプがいっぱいになります。一般に、意図を使用してカメラで画像を撮影している場合、uri結果として画像が取得され、縮小画像として読み取られ、同じ場所に保存されます

于 2013-04-17T12:43:37.660 に答える
0
BitmapFactory.Options optionsSignature = new BitmapFactory.Options();
final Bitmap bitmapSignature = BitmapFactory.decodeFile(
fileUriSignature.getPath(), optionsSignature);
Bitmap resizedSignature = Bitmap.createScaledBitmap(
                bitmapSignature, 256, 128, true);
signature.setImageBitmap(resizedSignature);
于 2016-04-26T04:33:51.143 に答える