0

私は、ギャラリーまたはカメラのAndroidから取得した画像をサーバーにアップロードすることを学んでいます....

ギャラリーまたはカメラから画像デコードを使用して imageview に取得した後に画像を表示すると、画像はぼやけません... しかし、アップロードした後、画像のようなサイズが小さくぼやけます..

どこが間違っているのかわかりません。デコードされた画像かアップロード画像

ここに私のコードの一部

デコードコード

public void decodeFile(String filePath) {
    // Decode image size
    BitmapFactory.Options o = new BitmapFactory.Options();
    o.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(filePath, o);

    // The new size we want to scale to
    final int REQUIRED_SIZE = 1024;

    // Find the correct scale value. It should be the power of 2.
    int width_tmp = o.outWidth, height_tmp = o.outHeight;
    int scale = 1;
    while (true) {
        if (width_tmp < REQUIRED_SIZE && height_tmp < REQUIRED_SIZE)
            break;
        width_tmp /= 2;
        height_tmp /= 2;
        scale *= 2;
    }

    // Decode with inSampleSize
    BitmapFactory.Options o2 = new BitmapFactory.Options();
    o2.inSampleSize = scale;
    bitmap = BitmapFactory.decodeFile(filePath, o2);

    imgView.setImageBitmap(bitmap);

}

コードをアップロード

try {

            DatabaseHandler userDB = new DatabaseHandler(getApplicationContext());      
            HashMap<String, String> userDetail = userDB.getUserDetails();
            String uid= userDetail.get("uid");  

            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            bitmap.compress(CompressFormat.JPEG, 100, bos);
            byte[] data = bos.toByteArray();
            HttpClient httpClient = new DefaultHttpClient();                
            HttpPost postRequest = new HttpPost(PHP_URL);               
            ByteArrayBody bab = new ByteArrayBody(data,file_name);              
            MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
            reqEntity.addPart("uploadedfile", bab);
            postRequest.setEntity(reqEntity);
            HttpResponse response = httpClient.execute(postRequest);
            BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(),"UTF-8"));
            String sResponse;
            StringBuilder s = new StringBuilder();

            while ((sResponse = reader.readLine()) != null) {
                s = s.append(sResponse);
            }

            return s.toString().trim();

        } catch (Exception e) {

            err="error"+e.getMessage();
            Log.e(e.getClass().getName(), e.getMessage());

            return e.getMessage();
        }   

アップロードする前に、ImageView に画像を表示します ここに画像の説明を入力

アップロード後、リストビューで表示 ここに画像の説明を入力

誰でも私を助けてくれることを願っています。私の英語がうまくない場合は申し訳ありません...

4

1 に答える 1

-1

メソッドのドキュメントによると、画像を100パーセント圧縮しているため、品質が低下します

        bitmap.compress(CompressFormat.JPEG, 100, bos);

100 より小さい値を使用し、品質とサイズのバランスが取れるまで調整することをお勧めします

于 2013-10-11T10:28:52.043 に答える