实现拍摄功能像天才扫描相机

问题描述:

正是我想要相机的功能(如单和批次(每次多张照片))在以下应用:实现拍摄功能像天才扫描相机

https://play.google.com/store/apps/details?id=com.thegrizzlylabs.geniusscan.free&hl=en

我已经成功实施这一点。但是,我的问题是,我已经用SurfaceView实现了这个功能。当我从相机捕捉照片时,与Genius扫描应用程序相比,其模糊。

任何人都可以请让我知道我到底能够如何实现这个功能而不会模糊。

注:捕获多张照片

private void takeImage() { 
     camera.takePicture(null, null, new PictureCallback() { 

      private File imageFile; 

      @Override 
      public void onPictureTaken(byte[] data, Camera camera) { 
       try { 
        // convert byte array into bitmap 
        Bitmap loadedImage = null; 
        Bitmap rotatedBitmap = null; 
        loadedImage = BitmapFactory.decodeByteArray(data, 0, 
          data.length); 

        // rotate Image 
        Matrix rotateMatrix = new Matrix(); 
        rotateMatrix.postRotate(rotation); 
        rotatedBitmap = Bitmap.createBitmap(loadedImage, 0, 0, 
          loadedImage.getWidth(), loadedImage.getHeight(), 
          rotateMatrix, false); 
        String state = Environment.getExternalStorageState(); 
        File folder = null; 
        if (state.contains(Environment.MEDIA_MOUNTED)) { 
         folder = new File(Environment 
           .getExternalStorageDirectory() + "/Demo"); 
        } else { 
         folder = new File(Environment 
           .getExternalStorageDirectory() + "/Demo"); 
        } 

        boolean success = true; 
        if (!folder.exists()) { 
         success = folder.mkdirs(); 
        } 
        if (success) { 
         java.util.Date date = new java.util.Date(); 
         imageFile = new File(folder.getAbsolutePath() 
           + File.separator 
           + new Timestamp(date.getTime()).toString() 
           + "Image.jpg"); 

         imageFile.createNewFile(); 
        } else { 
         Toast.makeText(getBaseContext(), "Image Not saved", 
           Toast.LENGTH_SHORT).show(); 
         return; 
        } 

        ByteArrayOutputStream ostream = new ByteArrayOutputStream(); 

        // save image into gallery 
        rotatedBitmap.compress(CompressFormat.JPEG, 100, ostream); 

        FileOutputStream fout = new FileOutputStream(imageFile); 
        fout.write(ostream.toByteArray()); 
        fout.close(); 
        ContentValues values = new ContentValues(); 

        values.put(Images.Media.DATE_TAKEN, 
          System.currentTimeMillis()); 
        values.put(Images.Media.MIME_TYPE, "image/jpeg"); 
        values.put(MediaStore.MediaColumns.DATA, 
          imageFile.getAbsolutePath()); 

        CameraDemoActivity.this.getContentResolver().insert(
          Images.Media.EXTERNAL_CONTENT_URI, values); 

        if (mSingleView.getVisibility() == View.VISIBLE) { 
         btnDoneClicked(); 
        } else { 

        } 


        mArrayUri.add(Uri.fromFile(imageFile)); 

        if (mBatchView.getVisibility() == View.VISIBLE) { 
         batchClickCount++; 
         mtxtCapturedClicks.setText(String.valueOf(batchClickCount)); 
        } else { 
         batchClickCount = 0; 
         mtxtCapturedClicks.setText(""); 
        } 

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

      } 
     }); 
    } 
+0

我碰上了一个类似的问题一次。你在'''onActivityResult'''中使用额外的“数据”吗?如果您看[简单拍摄照片](https://developer.android.com/training/camera/photobasics.html)教程,那么额外只是一个缩略图,您需要在拍摄照片中提供一个文件URI意图保存完整大小的图像。 – Haem

public static Bitmap scaleBitmap(Bitmap bitmap, int newWidth, int newHeight) { 
    Bitmap scaledBitmap = Bitmap.createBitmap(newWidth, newHeight, Bitmap.Config.ARGB_8888); 

    float scaleX = newWidth/(float) bitmap.getWidth(); 
    float scaleY = newHeight/(float) bitmap.getHeight(); 
    float pivotX = 0; 
    float pivotY = 0; 

    Matrix scaleMatrix = new Matrix(); 
    scaleMatrix.setScale(scaleX, scaleY, pivotX, pivotY); 

    Canvas canvas = new Canvas(scaledBitmap); 
    canvas.setMatrix(scaleMatrix); 
    canvas.drawBitmap(bitmap, 0, 0, new Paint(Paint.FILTER_BITMAP_FLAG)); 

    return scaledBitmap; 
} 

试试这个功能来提高图像质量