Convert Image format in android java

10,721

You didn't post any of your code, so i have no idea what is wrong with your code. but you can convert a image to PNG or JPEG like this:

try {
   FileOutputStream out = new FileOutputStream(filename);
   bmp.compress(Bitmap.CompressFormat.PNG, 100, out); //100-best quality
   out.close();
} catch (Exception e) {
   e.printStackTrace();
}
Share:
10,721
Shubham Naik
Author by

Shubham Naik

Android App Developer

Updated on June 27, 2022

Comments

  • Shubham Naik
    Shubham Naik almost 2 years

    How do i convert Image format from within my android application activity.

    I have the code to convert image format using Java, but it doesn't output the image with good quality and also similar code is not working in Android's Java.

  • Shubham Naik
    Shubham Naik about 10 years
    from Bitmap to JPG? what is a Bitmap den? another format? I want to convert from PNG to JPG or vice versa.
  • Luciano
    Luciano about 10 years
    A bitmap of your image (input)
  • Shubham Naik
    Shubham Naik about 10 years
    here is my code in android, but where do i put my original image url 'public class Main extends Activity { Bitmap bmp; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); try{ FileOutputStream out = new FileOutputStream("jjj.jpg"); bmp.compress(Bitmap.CompressFormat.PNG,100,out); out.close(); } catch(Exception e) { e.printStackTrace(); } } }'
  • Guillermo Merino
    Guillermo Merino about 10 years
    It depends on which image are you pretending to convert? do you have it in your phone, do you receive it through internet... ?
  • Guillermo Merino
    Guillermo Merino about 10 years
    You can use Bitmap bm = BitmapFactory.decodeFile(yourPath);
  • Shubham Naik
    Shubham Naik about 10 years
    so BitmapFactory.decode() will initialize my Bitmap object to the image, is it correct?
  • CrackerKSR
    CrackerKSR about 2 years
    And what about Gif and animated webp which has multiple frames