2

完全な品質を維持するために、圧縮せずに画像をサーバーにアップロードしようとしています。

次の方法を見つけました:

compress(Bitmap.CompressFormat.JPEG, 100, bao);

しかし、私の場合はうまくいきません。元のイメージは 2 MB ですが、サーバー上では 60 KB しかありません。

画像キャプチャは次のコードを使用しています

Intent i=new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i,camdata);


protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
    if(resultCode==RESULT_OK) {
        Bundle bn=data.getExtras();
        bm=(Bitmap)bn.get("data");
        imageview.setImageBitmap(bm);
        imageview.setClickable(false);
        ByteArrayOutputStream bao = new ByteArrayOutputStream();
        BitmapFactory.Options options=new BitmapFactory.Options();
        options.inSampleSize=6;
        final float scale=getResources().getDisplayMetrics().density;
        Display dis=getWindowManager().getDefaultDisplay();
        int width=dis.getWidth();
        scalebmp=Bitmap.createScaledBitmap(bm,400,300, true);
        scalebmp.compress(Bitmap.CompressFormat.JPEG, 100, bao);

        byte [] ba = bao.toByteArray();
        String imgstr=Base64.encodeToString(ba,Base64.DEFAULT);
    }
}
4

3 に答える 3