拍摄和保存的画面,指定大小(单位为KB-S)画面、大小、单位、KB

2023-09-03 23:02:55 作者:努力,努力,不要放弃.

在我的应用我拍张照片并将其保存在指定的方式。我的手机是Nexus的4,相机是非常强的,每一个画面是约2.31MB我怎么能保存图片例如在60KB? 我能做到这一点与code?怎么样?

 文件NEWDIR =新的文件(目录);
         如果(!newdir.exists()){
             newdir.mkdirs();
         }
        picturesCount ++;
        JPG字符串文件= DIR + picturesCount +;
        的ImagePath =文件;
        文件的newfile =新的文件(文件);
        尝试 {
            newfile.createNewFile();
        }赶上(IOException异常E){}
        乌里outputFileUri = Uri.fromFile(newfile中);
        意图cameraIntent =新的意图(MediaStore.ACTION_IM​​AGE_CAPTURE);
        cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,outputFileUri);
        startActivityForResult(cameraIntent,TAKE_PHOTO_ code);
 

解决方案 怎么调整photoshop中字体像素点的大小如何将PS中字体单位大小 点 改为 像素

当你使用相机和拍摄照片后,可以执行以下方法中的任务,以减少图像的质量和类型如JPEG或PNG (PNG花费的时间比JPEG 更多的空间),所以刚与值(60目前的满分100分)播放,看到了差距大小

  @覆盖
公共无效onPictureTaken(byte []的数据,摄像头摄像头){
    InputStream的时间=新ByteArrayInputStream的(数据);

    BitmapFactory.Options选项=新BitmapFactory.Options();
    位图preview_bitmap = BitmapFactory.de codeStream(在,空,期权);
    ByteArrayOutputStream流=新ByteArrayOutputStream();
    preview_bitmap.com preSS(Bitmap.Com pressFormat.JPEG,60,流);
    字节[]的字节数组= stream.toByteArray();

    FileOutputStream中outStream = NULL;
    尝试 {
        outStream =新的FileOutputStream(新文件(
                Environment.getExternalStorageDirectory(),Image1.jpg));
        outStream.write(字节阵列);
        outStream.close();
    }赶上(FileNotFoundException异常E){
        Log.d(照相机,e.getMessage());
    }赶上(IOException异常E){
        Log.d(照相机,e.getMessage());
    }
}
 

in my app I take a picture and save it in specified way. My phone is Nexus 4 and the camera is very strong and every picture is about 2.31MB how can I save picture for example in 60KB? Can I do it with code? and how?

File newdir = new File(dir);
         if(!newdir.exists()){
             newdir.mkdirs();
         }
        picturesCount++;
        String file = dir+picturesCount+".jpg";
        imagePath = file;
        File newfile = new File(file);
        try {
            newfile.createNewFile();
        } catch (IOException e) {}       
        Uri outputFileUri = Uri.fromFile(newfile);
        Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
        cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        startActivityForResult(cameraIntent, TAKE_PHOTO_CODE);

解决方案

When you are using camera and picture is taken, you can perform the task in the method below to reduce the quality of the image and type like JPEG or PNG (PNG takes more space than JPEG) so just play with the value (60 current out of 100) and see the difference in size.

@Override
public void onPictureTaken(byte[] data, Camera camera) {
    InputStream in = new ByteArrayInputStream(data);

    BitmapFactory.Options options = new BitmapFactory.Options();
    Bitmap preview_bitmap = BitmapFactory.decodeStream(in, null, options);
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    preview_bitmap.compress(Bitmap.CompressFormat.JPEG, 60, stream);
    byte[] byteArray = stream.toByteArray();

    FileOutputStream outStream = null;
    try {
        outStream = new FileOutputStream(new File(
                Environment.getExternalStorageDirectory(), "Image1.jpg"));
        outStream.write(byteArray);
        outStream.close();
    } catch (FileNotFoundException e) {
        Log.d("CAMERA", e.getMessage());
    } catch (IOException e) {
        Log.d("CAMERA", e.getMessage());
    }
}