0

カメラから写真を撮ると、300〜500 KB(1800 X 1700 px)のサイズの画像が表示されます。

しかし、アプリケーションから写真を撮ると、サイズが30〜50 KB(150 X 200 px)の画像が表示されます。

150 x200pxを300x400 pxのようなサイズに変更するにはどうすればよいですか?

この画像を送信するサーバーは、280 x360pxのサイズ未満の画像を受け入れないためです。

私が現在使用しているコードは次のとおりです。

Bitmap bit = (Bitmap) data.getExtras().get("data");
ByteArrayOutputStream bao = new ByteArrayOutputStream();
bit.compress(Bitmap.CompressFormat.JPEG, 100, bao);
byte[] ba = bao.toByteArray();
File imagesFolder = new File(Environment.getExternalStorageDirectory(), "My - Images");
File f = new File(imagesFolder, "test.jpg");
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(ba);
fo.flush();
fo.close();

画像を圧縮していませんが、ホーム画面からカメラを使用して撮影した画像と比較して、画像サイズが10分の1になります。

ありがとうございました

4

3 に答える 3

1

新しいビットマップオブジェクトを作成し、それを使用する必要がありますBitmap.createScaledBitmap()

Bitmap bit = (Bitmap) data.getExtras().get("data");
Bitmap bitmap =Bitmap.createScaledBitmap(bit, newWidth, newHeight, filter);
// use bitmap instead of bit object
于 2012-09-26T07:41:46.537 に答える
1

フルサイズのカメラ画像を取得するには、カメラを向けて画像を一時ファイルに保存する必要があります。あなただけが実際のサイズの画像を取得できます。

intent = new Intent("android.media.action.IMAGE_CAPTURE");
File photo;
try
{
    // place where to store camera taken picture
    photo = this.createTemporaryFile("picture", ".jpg");
    photo.delete();
}
catch(Exception e)
{
    Log.v(TAG, "Can't create file to take picture!");
    Toast.makeText(activity, "Please check SD card! Image shot is impossible!", 10000);
    return false;
}
mImageUri = Uri.fromFile(photo);
intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri);
//start camera intent
activity.startActivityForResult(this, intent, MenuShootImage);

private File createTemporaryFile(String part, String ext) throws Exception
{
File tempDir= Environment.getExternalStorageDirectory();
tempDir=new File(tempDir.getAbsolutePath()+"/.temp/";
if(!tempDir.exists())
{
    tempDir.mkdir();
}
return File.createTempFile(part, ext, tempDir);
}

次に、画像キャプチャ インテントが機能し終わったら、次のコードを使用して imageUri から画像を取得します。

public void grabImage(ImageView imageView)
{
this.getContentResolver().notifyChange(mImageUri, null);
ContentResolver cr = this.getContentResolver();
Bitmap bitmap;
try
{
    bitmap = android.provider.MediaStore.Images.Media.getBitmap(cr, mImageUri);
    imageView.setImageBitmap(bitmap);
}
catch (Exception e)
{
    Toast.makeText(this, "Failed to load", Toast.LENGTH_SHORT).show();
    Log.d(TAG, "Failed to load", e);
}
}


//called after camera intent finished
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent)
{
if(requestCode==MenuShootImage && resultCode==RESULT_OK)
{
   ImageView imageView;
   //... some code to inflate/create/find appropriate ImageView to place grabbed image
   this.grabImage(imageView);
}
super.onActivityResult(requestCode, resultCode, intent);
}
于 2012-09-26T07:41:53.543 に答える
0

写真を撮る前に、カメラを設定する必要があります。

最初

   camera.open();

サポートされている画像サイズを確認してください。

   Camera.Parameters p = camera.getParameters();
   List<Size> ss = p.getSupportedPictureSizes();
   Iterator<Size> it = ss.iterator();
   Size sizeIWant = null;
   while(it.hasNext()){
   Size s = it.next();
       <compute sizeIWant based on various sizes provided>
   }
   p.setPictureSize(sizeIWant.width, sizeIWant.height);
   camera.setParameters(p);

次に、写真(コード)を撮ります。電話することを忘れないでくださいcamera.release()

于 2012-09-26T07:52:04.377 に答える