使用ACTION_IMAGE_CAPTURE时如何提高相机图像分辨率

时间:2014-01-15 06:26:02

标签: android camera android-camera resolution

我在我的应用中使用相机图像。当我从相机拍照时,目前的分辨率是195x260,但我需要600x400。谁能帮我。下面是关于相机分辨率的我的类课程

public static boolean isNetworkAvailable(Context ctx) {
            ConnectivityManager connectivityManager = (ConnectivityManager) ctx
                    .getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo activeNetworkInfo = connectivityManager
                    .getActiveNetworkInfo();
            return activeNetworkInfo != null
                    && activeNetworkInfo.isConnectedOrConnecting();
        }

        public static String getUUID() {
            UUID uuid = UUID.randomUUID();
            return String.valueOf(uuid);
        }

        // //////////////////////
        public static String getCompressedFilePath(String oPath, String name) {

            String uploadPath = oPath;
            BitmapFactory.Options o = new BitmapFactory.Options();
            o.inJustDecodeBounds = true;
            BitmapFactory.decodeFile(oPath, o);
            int owidth = o.outWidth;
            int oheight = o.outHeight;
            System.gc();
            Bitmap bitmap;
            try {
                bitmap = decodeFile(oPath);
                if (bitmap == null)
                    throw new Exception();
            } catch (Exception e) {
                e.printStackTrace();
                // stop the work as there is no more memory available
                return (null);
            }

            int height = bitmap.getHeight();
            int width = bitmap.getWidth();

            if (owidth > width || oheight > height) {
                try {
                    String oName = name;
                    File myDirectory = new File(
                            Environment.getExternalStorageDirectory() + "/IMAGES/");
                    myDirectory.mkdirs();
                    File file = new File(myDirectory, oName);
                    uploadPath = myDirectory + "/" + oName;
                    FileOutputStream fos = new FileOutputStream(file);
                    bitmap.compress(CompressFormat.JPEG, 100, fos);
                    // bitmap.recycle();
                    fos.flush();
                    fos.close();

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

            return uploadPath;
        }

        public static void writeBitmapToSD(Bitmap bitmap, String name) {

            if (bitmap == null)
                return;

            try {
                String oName = name;
                File myDirectory;
                myDirectory = new File(Environment.getExternalStorageDirectory()
                        + "/PMGRMS/");
                myDirectory.mkdirs();
                File file = new File(myDirectory, oName);
                FileOutputStream fos = new FileOutputStream(file);
                bitmap.compress(CompressFormat.JPEG, 100, fos);
                // bitmap.recycle();
                // uploadPath = myDirectory + "/" + oName;
                fos.flush();
                fos.close();

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

        }

        public static Bitmap decodeFile(String path) {
            // Decode image size
            BitmapFactory.Options o = new BitmapFactory.Options();
            o.inJustDecodeBounds = true;
            BitmapFactory.decodeFile(path, 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;
            }

            System.gc();
            // Decode with inSampleSize
            BitmapFactory.Options o2 = new BitmapFactory.Options();
            o2.inSampleSize = scale;
            Bitmap sBitmap;

            try {
                sBitmap = BitmapFactory.decodeFile(path, o2);
                if (sBitmap == null)
                    throw new Exception();
                System.gc();
                return sBitmap;

            } catch (Exception e) {
                e.printStackTrace();
                // stop the work as there is no more memory available
                return (null);
            }

        }

0 个答案:

没有答案