hi,

I would like to save a .bmp image using showSaveDialog and i cannot figure out what to use.. Below i have the code of open.

Code

protected void Open(JFileChooser chooser, JLabel lblPicture) {
		// TODO Auto-generated method stub
		if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION)
		{
			File fileChoosed = chooser.getSelectedFile();
			try 
			{
				imageChoosed = ImageIO.read(fileChoosed);
				lblPicture.setIcon(new ImageIcon(imageChoosed));	
				IconEnableing(true);
			} 
			
			catch (IOException e) 
			{
				e.printStackTrace();				
			}

You should be able to use the same basic structure as you did with the open(0 method, but use ImageIO.write() to write the image out to file. Similar to this

if (chooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
    File fileChoosen = chooser.getSelectedFile();
    try {
        ImageIO.write(img,"bmp",fileChoosen);
        ...

You may want to also take a look at the tutorial on saving an image:http://download.oracle.com/javase/tutorial/2d/images/saveimage.html

it saved but it saved as File not as an image.

it saved but it saved as File not as an image.

What do you mean? Did it save but when you double click on the file in window it comes up with "Choose the program you wish to open this file with" dialog?

If that is the case make sure you have the file extension right. If you are saving it as a JPEG add the .jpg

What do you mean? Did it save but when you double click on the file in window it comes up with "Choose the program you wish to open this file with" dialog?

If that is the case make sure you have the file extension right. If you are saving it as a JPEG add the .jpg

thank you very much i figured out that when i was saving the image i did not write the extenstion after the name. thx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.