首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >实现相机功能,如天才扫描相机

实现相机功能,如天才扫描相机
EN

Stack Overflow用户
提问于 2017-03-06 12:40:05
回答 1查看 120关注 0票数 0

我想要相机的功能(像单一和批处理(一次多张照片)在以下应用程序中):

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

我已经成功地实现了这一点。但是,我的问题是,我已经用SurfaceView实现了这个功能。当我从相机拍摄照片时,它与天才扫描应用程序相比模糊不清。

有谁能让我知道我怎样才能在不模糊的情况下实现这个功能。

注意:捕获多张照片

代码语言:javascript
复制
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();
                }

            }
        });
    }
EN

回答 1

Stack Overflow用户

发布于 2017-03-06 12:50:12

代码语言:javascript
复制
 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;
}

尝试此功能以提高图像质量。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42625919

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档