G
ganeshgebhard
Guest
Hi,
Im building a program in C# thats converts any image file to JPG, PNG, Icon or Bitmap.
But if I convert a file to Icon and I want to use this file in my VS project it wont read the file and sees it as an error.
Can somebody help me?
The whole Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Image_Converter
{
public partial class Form1 : Form
{
string CurrentFile;
Image img;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void SluitenToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void OpenenMenustrip_Click(object sender, EventArgs e)
{
openFileDialog1.Title = "Openen";
openFileDialog1.Filter = "All Files|*.*|JPEG|*.jpg|PNG|*.png|Icon|*.ico|Bitmap|*.bmp|GIF|*.gif|TIFF|*.tif|Enhanced Windows MetaFile|*.emf|Exchangeable Image File|*.exif|Windows MetaFile|*.wmf";
openFileDialog1.DefaultExt = "bmp";
openFileDialog1.FilterIndex = 1;
openFileDialog1.FileName = "";
openFileDialog1.ShowDialog();
if (openFileDialog1.FileName == "")
return;
CurrentFile = openFileDialog1.FileName.ToString();
img = Image.FromFile(openFileDialog1.FileName);
pictureBox1.Image = img;
}
private void JPEGMenustrip_Click(object sender, EventArgs e)
{
string newName = System.IO.Path.GetDirectoryName(CurrentFile);
newName = newName + ".jpg";
try
{
img.Save(newName, ImageFormat.Bmp);
}
catch
{
MessageBox.Show("Opslaan van JPEG-Bestand Mislukt.", "Mislukt", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
MessageBox.Show("Afbeelding Opgeslagen in " + newName.ToString(), "Afbeeling Opgeslagen", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void PNGMenustrip_Click(object sender, EventArgs e)
{
string newName = System.IO.Path.GetDirectoryName(CurrentFile);
newName = newName + ".png";
try
{
img.Save(newName, ImageFormat.Bmp);
}
catch
{
MessageBox.Show("Opslaan van PNG-Bestand Mislukt.", "Mislukt", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
MessageBox.Show("Afbeelding Opgeslagen in " + newName.ToString(), "Afbeeling Opgeslagen", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void IconMenustrip_Click(object sender, EventArgs e)
{
string newName = System.IO.Path.GetDirectoryName(CurrentFile);
newName = newName + ".ico";
try
{
img.Save(newName, ImageFormat.Bmp);
}
catch
{
MessageBox.Show("Opslaan van Icon-Bestand Mislukt.", "Mislukt", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
MessageBox.Show("Afbeelding Opgeslagen in " + newName.ToString(), "Afbeeling Opgeslagen", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void BitmapMenustrip_Click(object sender, EventArgs e)
{
string newName = System.IO.Path.GetFileNameWithoutExtension(CurrentFile);
newName = newName + ".bmp";
try
{
img.Save(newName, ImageFormat.Bmp);
}
catch
{
MessageBox.Show("Opslaan van Bitmap-Bestand Mislukt.", "Mislukt", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
MessageBox.Show("Afbeelding Opgeslagen in " + newName.ToString(), "Afbeeling Opgeslagen", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
Continue reading...
Im building a program in C# thats converts any image file to JPG, PNG, Icon or Bitmap.
But if I convert a file to Icon and I want to use this file in my VS project it wont read the file and sees it as an error.
Can somebody help me?
The whole Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Image_Converter
{
public partial class Form1 : Form
{
string CurrentFile;
Image img;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void SluitenToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void OpenenMenustrip_Click(object sender, EventArgs e)
{
openFileDialog1.Title = "Openen";
openFileDialog1.Filter = "All Files|*.*|JPEG|*.jpg|PNG|*.png|Icon|*.ico|Bitmap|*.bmp|GIF|*.gif|TIFF|*.tif|Enhanced Windows MetaFile|*.emf|Exchangeable Image File|*.exif|Windows MetaFile|*.wmf";
openFileDialog1.DefaultExt = "bmp";
openFileDialog1.FilterIndex = 1;
openFileDialog1.FileName = "";
openFileDialog1.ShowDialog();
if (openFileDialog1.FileName == "")
return;
CurrentFile = openFileDialog1.FileName.ToString();
img = Image.FromFile(openFileDialog1.FileName);
pictureBox1.Image = img;
}
private void JPEGMenustrip_Click(object sender, EventArgs e)
{
string newName = System.IO.Path.GetDirectoryName(CurrentFile);
newName = newName + ".jpg";
try
{
img.Save(newName, ImageFormat.Bmp);
}
catch
{
MessageBox.Show("Opslaan van JPEG-Bestand Mislukt.", "Mislukt", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
MessageBox.Show("Afbeelding Opgeslagen in " + newName.ToString(), "Afbeeling Opgeslagen", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void PNGMenustrip_Click(object sender, EventArgs e)
{
string newName = System.IO.Path.GetDirectoryName(CurrentFile);
newName = newName + ".png";
try
{
img.Save(newName, ImageFormat.Bmp);
}
catch
{
MessageBox.Show("Opslaan van PNG-Bestand Mislukt.", "Mislukt", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
MessageBox.Show("Afbeelding Opgeslagen in " + newName.ToString(), "Afbeeling Opgeslagen", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void IconMenustrip_Click(object sender, EventArgs e)
{
string newName = System.IO.Path.GetDirectoryName(CurrentFile);
newName = newName + ".ico";
try
{
img.Save(newName, ImageFormat.Bmp);
}
catch
{
MessageBox.Show("Opslaan van Icon-Bestand Mislukt.", "Mislukt", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
MessageBox.Show("Afbeelding Opgeslagen in " + newName.ToString(), "Afbeeling Opgeslagen", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void BitmapMenustrip_Click(object sender, EventArgs e)
{
string newName = System.IO.Path.GetFileNameWithoutExtension(CurrentFile);
newName = newName + ".bmp";
try
{
img.Save(newName, ImageFormat.Bmp);
}
catch
{
MessageBox.Show("Opslaan van Bitmap-Bestand Mislukt.", "Mislukt", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
MessageBox.Show("Afbeelding Opgeslagen in " + newName.ToString(), "Afbeeling Opgeslagen", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
Continue reading...