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();
}
Comments
-
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 about 10 yearsfrom Bitmap to JPG? what is a Bitmap den? another format? I want to convert from PNG to JPG or vice versa.
-
Luciano about 10 yearsA bitmap of your image (input)
-
Shubham Naik about 10 yearshere 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 about 10 yearsIt depends on which image are you pretending to convert? do you have it in your phone, do you receive it through internet... ?
-
Guillermo Merino about 10 yearsYou can use Bitmap bm = BitmapFactory.decodeFile(yourPath);
-
Shubham Naik about 10 yearsso BitmapFactory.decode() will initialize my Bitmap object to the image, is it correct?
-
CrackerKSR about 2 yearsAnd what about Gif and animated webp which has multiple frames