Results 1 to 13 of 13
- 04-07-2011, 07:19 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 52
- Rep Power
- 0
How to Convert .jpg to .bmp Image Format
Hi All,
I Need to convert .jpg file to a .bmp file, When i am trying to convert it the converted image could not opening.
//Create file for the source
File input = new File("c:/temp/image.jpg");
//Read the file to a BufferedImage
BufferedImage image = ImageIO.read(input)
//Create a file for the output
File output = new File("c:/temp/image.bmp");
//Write the image to the destination as a JPG
ImageIO.write(image, "bmp", output);
I am Trying Above code to try this can any one suggest how to do this without changing the quality.
Waiting for Positive Comments which will help me Out.
Thanks in Advance....
- 04-07-2011, 07:39 AM #2
To get better help sooner, post a SSCCE that clearly demonstrates your problem.
And post your code in code tags, not that silly bold font.
db
- 04-07-2011, 07:47 AM #3
Member
- Join Date
- Mar 2011
- Posts
- 52
- Rep Power
- 0
Thanks Mr.Darryl.Burke,
Sorry For that Bold Font. Here is the code which i am using
Java Code:import java.io.*; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; public class ConvertJPGToBMP { public static void main(String a[]){ try{ System.out.println("Enter image name\n"); BufferedReader bf=new BufferedReader(new InputStreamReader(System.in)); String imageName=bf.readLine(); File input = new File(imageName); BufferedImage image = ImageIO.read(input); System.out.println("Enter the output image name(.bmp):\n"); String imageName1=bf.readLine(); File output = new File(imageName1); ImageIO.write(image, "bmp", output); System.out.println("Your image has been converted successfully"); }catch(FileNotFoundException e){ System.out.println("Error:"+e.getMessage()); }catch(IOException e) { System.out.println("Error:"+e.getMessage()); } catch(Exception e){ System.out.println(e.getMessage()); } } }
- 04-07-2011, 11:02 AM #4
Member
- Join Date
- Apr 2011
- Location
- Athens, Greece
- Posts
- 52
- Rep Power
- 0
First of all what is the output of this? Doesn't compile? Some error? Doesn't do anything? Help us a bit. Second you could check How to Use File Choosers (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components) instead of entering a name of a file which you could spell wrong or whatever.
- 04-07-2011, 11:09 AM #5
Member
- Join Date
- Apr 2011
- Location
- Athens, Greece
- Posts
- 52
- Rep Power
- 0
Think I found your error. On the "System.out.println("Enter the output image name(.bmp):\n");" if you write the whole destination path (e.g. C:\new.bmp) it works. So find a way to get the source path and pass it to the destination ;)
- 04-07-2011, 11:17 AM #6
Member
- Join Date
- Mar 2011
- Posts
- 52
- Rep Power
- 0
Thanks santeron,
I Need to convert the Files which are on specific location into my system.then all files have to me same name as previous just need to convert to bmp.
eg. d:\Newfolder\ 1.jpg, 2.jpg,3.jpg
output : d:\output\1.bmp,2.bmp,3.bmp
How can i achive this.
thanks in advance
- 04-07-2011, 11:31 AM #7
What's holding you back from answering santeron's question?
dbFirst of all what is the output of this? Doesn't compile? Some error? Doesn't do anything?
- 04-07-2011, 11:33 AM #8
Member
- Join Date
- Apr 2011
- Location
- Athens, Greece
- Posts
- 52
- Rep Power
- 0
If you want to convert multiple files you could either do a while loop for the user to enter one by one the files or you could set a source path for the app to search by it's own, get files and convert those ending in .jpg which is a little harder. Let's say you go for the first option and do a while loop. You could have some code looking like this:
You could try doing it with fileChoosers both for opening and saving for easy folder change :)Java Code:Enter source folder Enter destination folder while (true) { enter file name (which should be in source folder) if file exists { convert file to bmp and put it in output folder show message of success } else { show error message ask if he wants to convert another file (y/n) if (y) { continue; } else { system.exit(0); } ask if he wants to convert another file (y/n) if (n) { system.exit(0); (or brake;) } } //end loop
- 04-07-2011, 11:37 AM #9
Member
- Join Date
- Mar 2011
- Posts
- 52
- Rep Power
- 0
Hello Darryl,
Sorry for same, But as he mentioned that there could be only one problem of entering the file name with complete path can be.
Can You suggest me How i can convert an array of images(.jpg) files to (.bmp) files.
Please come with Suggestion.
Thanks.
- 04-07-2011, 11:41 AM #10
Member
- Join Date
- Mar 2011
- Posts
- 52
- Rep Power
- 0
Thanks Mr.santeron,
This will help me a Lot, Can you tell me brief about the second way u suggested to me.
- 04-07-2011, 11:45 AM #11
Member
- Join Date
- Apr 2011
- Location
- Athens, Greece
- Posts
- 52
- Rep Power
- 0
The use could write a series of file names delimited by a certain character like ";" or whatever. So lets say he wrote "image1.jpg image2.jpg" (i used space as the delimiter) you take that String and use the split method of Strings.
String input = "image1.jpg image2.jpg";
String[] imageArray = input.split(" ");
now you have an array of strings that you can loop through.
- 04-07-2011, 11:50 AM #12
Member
- Join Date
- Apr 2011
- Location
- Athens, Greece
- Posts
- 52
- Rep Power
- 0
Check a couple of links I found on populating files in folder. Search/Read don't except us to tell you what to do. We could suggest or lead you to a conclusion ;)
Listing the Files or Subdirectories in a Directory | Example Depot
open and read all files from folder - Java
- 04-07-2011, 11:51 AM #13
Member
- Join Date
- Mar 2011
- Posts
- 52
- Rep Power
- 0
Similar Threads
-
convert .txt file in .csv format
By rajuchacha007 in forum New To JavaReplies: 19Last Post: 03-18-2010, 09:10 AM -
How Convert a Byte array to a image format
By perlWhite in forum New To JavaReplies: 2Last Post: 08-23-2009, 08:11 PM -
How Convert a Byte array to a image format
By perlWhite in forum Advanced JavaReplies: 1Last Post: 08-22-2009, 07:05 PM -
how to convert one format to another format
By mahipal_reddy621 in forum New To JavaReplies: 1Last Post: 12-02-2008, 10:21 AM -
how to convert date format
By saran123 in forum New To JavaReplies: 5Last Post: 10-16-2008, 06:10 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks