PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, May 6, 2022

[FIXED] How to make high resolution image

 May 06, 2022     android, image     No comments   

Issue

I have made an app that uses the filter image and save in sdcard it's working good but I want to save image in two resolution high and low, I have never tried on resolution, Any one one can help that how to save in these both resolution? My code is below

private void saveBitmap(Bitmap bmp, String fileName, int resolution, String resolutionQuality) {
    // File f = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + fileName + ".png");
    File f = new File(Environment.getExternalStorageDirectory() + "FiltureImages");
    if (!f.exists()) {
        File wallpaperDirectory = new File("/sdcard/FiltureImages/");
        wallpaperDirectory.mkdirs();
    }
    File file = new File(new File("/sdcard/FiltureImages/"), fileName + resolutionQuality + ".png");
    if (file.exists()) {
        file.delete();
    }
    try {
        fos = new FileOutputStream(file);

        bmp.compress(Bitmap.CompressFormat.PNG, resolution, fos);
        Toast.makeText(mActivity, "Image save successfully", Toast.LENGTH_SHORT).show();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}

Solution

Call like this saveBitmap(bm, "high", "low", 100, 0, "quality");

Quality range from 0 -100

Note: change Bitmap.CompressFormat.PNG to Bitmap.CompressFormat.JPEG beacuse quality works with JPEG format.

private void saveBitmap(Bitmap bmp, String fileNameHigh, String fileNameLow, int resolutionHigh, int resolutionLow, String resolutionQuality) {

        File f = new File(Environment.getExternalStorageDirectory() + "FiltureImages");
        if (!f.exists()) {
            f.mkdirs();
        }
        File file = new File(f, fileNameHigh + resolutionQuality + ".png");
        if (file.exists()) {
            file.delete();
        }
        File file1 = new File(f, fileNameLow + resolutionQuality + ".png");
        if (file1.exists()) {
            file1.delete();
        }
        try {
            FileOutputStream high = new FileOutputStream(file);
            FileOutputStream low = new FileOutputStream(file1);

            bmp.compress(Bitmap.CompressFormat.JPEG, resolutionHigh, high);
            bmp.compress(Bitmap.CompressFormat.JPEG, resolutionLow, low);
            Toast.makeText(this, "Image save successfully", Toast.LENGTH_SHORT).show();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            Toast.makeText(this, "Image save falid", Toast.LENGTH_SHORT).show();
        }
    }


Answered By - Sohail Zahid
Answer Checked By - Terry (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing