2016-03-16 2 views
0

Я делаю приложение для захвата изображения с использованием намерения и изменения размера изображения в соответствии со мной, но он размыт после захвата, поэтому мне нужно принять предложения и помочь. На самом деле, я делаю переориентацию изображения по шкале «Создание масштабированного растрового изображения» и хочу скрытое изображение небольшого размера, но после повторной калибровки в малом размере размыты.re-size my image without blur

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if (requestCode == 1 && resultCode == RESULT_OK) { 
     try { 
      if (requestCode == 1) { 
       if (data != null && data.getExtras() != null && data.getExtras().get("data") != null) { 
        bitmap = (Bitmap) data.getExtras().get("data"); 

        int width = bitmap.getWidth(); 
        int height = bitmap.getHeight(); 
        int newWidth = 100; 
        int newHeight = 50; 
        float scaleWidth = ((float) newWidth)/width; 
        float scaleHeight = ((float) newHeight)/height; 

        Matrix matrix = new Matrix(); 
        // resize the bit map 
        matrix.postScale(scaleWidth, scaleHeight); 
        // rotate the Bitmap 

        Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); 

        int h = resizedBitmap.getHeight(); 

        int b = resizedBitmap.getWidth(); 
        Log.e("height & width ", h + "" + b); 

        Bitmap resized = Bitmap.createScaledBitmap(bitmap, 25, 25, true); 

        int h1 = bitmap.getHeight(); 
        int b1 = bitmap.getWidth(); 
        Log.e("height 1 & width 1", h1 + "" + b1); 

        mbPhotoImageViewId.setImageBitmap(resized); 
        int size = resized.getWidth() * resized.getHeight(); 
        ByteArrayOutputStream stream = new ByteArrayOutputStream(size); 
        resized.compress(Bitmap.CompressFormat.PNG, 100, stream); 

        byte[] image = stream.toByteArray(); 
        System.out.println("byte array:" + image.length + " " + image); 

        img_str = Base64.encodeToString(image, Base64.DEFAULT); 
        System.out.println("string: " + img_str.length() + " " + img_str); 

        Log.d("BITMAP form of image", image.toString()); 

       } 
      } 
     } catch (Exception e) { 
      e.toString(); 
      Toast.makeText(getApplicationContext(), " Error Code : C_M09004", Toast.LENGTH_LONG).show(); 
     } 
    } 
} 

ответ

0

в этом коде, вы должны передать вашу высоту желания и ширину в соответствии с этой высотой и шириной этой функции Копир.изобрами

public Bitmap Resizedoesnotlosequality(String tempDir, int reqwid, 
     int reqhei) { 

    Bitmap src = null; 

    try { 
     BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options(); 
     bmpFactoryOptions.inJustDecodeBounds = true; 

     Bitmap bm = BitmapFactory.decodeFile(tempDir, bmpFactoryOptions); 

     BitmapFactory.Options Options = new BitmapFactory.Options(); 
     Options.inJustDecodeBounds = false; 
     Options.inSampleSize = calculateInSampleSize(bmpFactoryOptions, 
       reqwid, reqhei); 
     bm = BitmapFactory.decodeFile(tempDir, Options); 

     Matrix matrix = new Matrix(); 
     // resize the bit map 

     // recreate the new Bitmap 
     bmpwid = bm.getWidth(); 
     bmphei = bm.getHeight(); 
     src = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), 
       matrix, true); 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } 

    return src; 
} 

public static int calculateInSampleSize(BitmapFactory.Options options, 
     int reqWidth, int reqHeight) { 
    final int height = options.outHeight; 
    final int width = options.outWidth; 
    int inSampleSize = 1; 

    if (height > reqHeight || width > reqWidth) { 

     while ((height/inSampleSize) > reqHeight 
       || (width/inSampleSize) > reqWidth) { 
      inSampleSize++; 
     } 
    } 

    return inSampleSize; 

} 
+0

Я сделал изменение размера, но моим образом будет Blurr – user3839710