Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在使用ACTION_image_CAPTURE时提高相机图像分辨率_Android_Camera_Android Camera_Resolution - Fatal编程技术网

Android 如何在使用ACTION_image_CAPTURE时提高相机图像分辨率

Android 如何在使用ACTION_image_CAPTURE时提高相机图像分辨率,android,camera,android-camera,resolution,Android,Camera,Android Camera,Resolution,我正在我的应用程序中使用相机图像。当我用相机拍照时,当前分辨率是195x260,但我需要600x400。有人能帮我吗。下面是关于相机分辨率的util类 public static boolean isNetworkAvailable(Context ctx) { ConnectivityManager connectivityManager = (ConnectivityManager) ctx .getSystemService(

我正在我的应用程序中使用相机图像。当我用相机拍照时,当前分辨率是195x260,但我需要600x400。有人能帮我吗。下面是关于相机分辨率的util类

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);
            }

        }
publicstaticboolearnisnetworkavailable(Context-ctx){
ConnectivityManager ConnectivityManager=(ConnectivityManager)ctx
.getSystemService(Context.CONNECTIVITY\u服务);
NetworkInfo activeNetworkInfo=connectivityManager
.getActiveNetworkInfo();
返回activeNetworkInfo!=null
&&activeNetworkInfo.isConnectedOrConnecting();
}
公共静态字符串getUUID(){
UUID UUID=UUID.randomUUID();
返回字符串.valueOf(uuid);
}
// //////////////////////
公共静态字符串getCompressedFilePath(字符串oPath,字符串名称){
字符串uploadPath=oPath;
BitmapFactory.Options o=新的BitmapFactory.Options();
o、 inJustDecodeBounds=true;
解码文件(oPath,o);
int-owidth=o.outWidth;
内高=外高;
gc();
位图;
试一试{
位图=解码文件(oPath);
如果(位图==null)
抛出新异常();
}捕获(例外e){
e、 printStackTrace();
//停止工作,因为没有更多可用内存
返回(空);
}
int height=bitmap.getHeight();
int width=bitmap.getWidth();
如果(宽度>宽度|高度>高度){
试一试{
字符串oName=name;
File myDirectory=新文件(
getExternalStorageDirectory()+“/IMAGES/”;
myDirectory.mkdirs();
File File=新文件(myDirectory,oName);
uploadPath=myDirectory+“/”+oName;
FileOutputStream fos=新的FileOutputStream(文件);
压缩(CompressFormat.JPEG,100,fos);
//bitmap.recycle();
fos.flush();
fos.close();
}捕获(例外e){
e、 printStackTrace();
}
}
返回上传路径;
}
公共静态void writeBitmapToSD(位图、字符串名称){
如果(位图==null)
返回;
试一试{
字符串oName=name;
文件目录;
myDirectory=新文件(Environment.getExternalStorageDirectory()
+“/PMGRMS/”;
myDirectory.mkdirs();
File File=新文件(myDirectory,oName);
FileOutputStream fos=新的FileOutputStream(文件);
压缩(CompressFormat.JPEG,100,fos);
//bitmap.recycle();
//uploadPath=myDirectory+“/”+oName;
fos.flush();
fos.close();
}捕获(例外e){
e、 printStackTrace();
}
}
公共静态位图解码文件(字符串路径){
//解码图像大小
BitmapFactory.Options o=新的BitmapFactory.Options();
o、 inJustDecodeBounds=true;
解码文件(路径,o);
//我们要扩展到的新尺寸
所需的最终int_SIZE=1024;
//找到正确的刻度值。它应该是2的幂。
内部宽度=o.向外宽度,高度=o.向外高度;
int标度=1;
while(true){
如果(宽度\u tmp<要求的\u尺寸和高度\u tmp<要求的\u尺寸)
打破
宽度_tmp/=2;
高度_tmp/=2;
比例*=2;
}
gc();
//用inSampleSize解码
BitmapFactory.Options o2=新的BitmapFactory.Options();
o2.inSampleSize=刻度;
位图sBitmap;
试一试{
sBitmap=BitmapFactory.decodeFile(路径,o2);
如果(sBitmap==null)
抛出新异常();
gc();
返回sBitmap;
}捕获(例外e){
e、 printStackTrace();
//停止工作,因为没有更多可用内存
返回(空);
}
}

我不能给你一个直接的答案,但也许这个链接会给你一些有用的信息,我甚至会称之为可能的重复…@Joel如果我想要800 X 600我需要在上面的代码中更改什么