Drag&Drop Image_coverter

Desarrollo de aplicaciones de escritorio C#, c++, Java, Net, VB... y todos los frameworks y tecnologías relacionadas co este tipo de aplicaciones.
Hala, otra app en C# que he realizado... es un conversor de imagenes utilizando D&D , la verdad que voy descubriendo cosillas y cada vez doy mas fe de la palabra de nuestro dios pabloko ,amen! XD , no hay color con ams.
captura:

Imagen

Source:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using System.Drawing.Drawing2D;
using System.Threading;
using DialogAbout;


namespace ImageConverter
{
public partial class Form1 : Form
{
protected Graphics myGraphics;

string skinFolder;
public Form1()
{
InitializeComponent();

}
private string[] FileList;

private void pictureBox1_DragDrop(object sender, DragEventArgs e)
{
FileList = (string[])e.Data.GetData(DataFormats.FileDrop, false);
label5.Text = " Images loaded [ " + FileList.Length + " ]";
pictureBox1.Image = Image.FromFile(FileList[0]);
Image Picture = Image.FromFile(FileList[0]);
if (numericUpDown1.Value == 10)
{
numericUpDown1.Value = Picture.Height;
}
if (numericUpDown2.Value == 10)
{
numericUpDown2.Value = Picture.Width;
}
SetImage(pictureBox1);
DisplayThumbnails();
}


private static System.Drawing.Imaging.ImageFormat formatt(string e)
{
switch (e)
{
case "Bmp":
return System.Drawing.Imaging.ImageFormat.Bmp;
case "Emf":
return System.Drawing.Imaging.ImageFormat.Emf;
case "Gif":
return System.Drawing.Imaging.ImageFormat.Gif;
case "Jpeg":
return System.Drawing.Imaging.ImageFormat.Jpeg;
case "Png":
return System.Drawing.Imaging.ImageFormat.Png;
case "Tiff":
return System.Drawing.Imaging.ImageFormat.Tiff;
case "Wmf":
return System.Drawing.Imaging.ImageFormat.Wmf;
case "Ico":
return System.Drawing.Imaging.ImageFormat.Icon;
default:
return System.Drawing.Imaging.ImageFormat.Jpeg;
}
}
private void DisplayThumbnails()
{
// clean up any thumbnails already present
while (this.panelThumbnails.Controls.Count > 0)
{
Thumbnail thumbnail = this.panelThumbnails.Controls[0] as Thumbnail;
thumbnail.Dispose();
this.panelThumbnails.Controls.Remove(thumbnail);
}
int numberHorizontal = -1;

foreach (string file in FileList)
{
Thumbnail thumbnail = null;
try
{

thumbnail = new Thumbnail(file);
}
catch (System.OutOfMemoryException)
{
thumbnail = null;
continue;
}
if (numberHorizontal < 0)
{
// determine how many thumbnails can be displayed on one row
numberHorizontal = (int)(this.panelThumbnails.Width / thumbnail.Width);
}
// set the position for the thumbnail and add it to the panel's controls
thumbnail.Left = 10 + (thumbnail.Width + 10) * (this.panelThumbnails.Controls.Count % numberHorizontal);
thumbnail.Top = 10 + (thumbnail.Height + 10) * (this.panelThumbnails.Controls.Count / numberHorizontal);
this.panelThumbnails.Controls.Add(thumbnail);
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{

}

private void label1_Click(object sender, EventArgs e)
{

}

private void pictureBox1_DragEnter(object sender, DragEventArgs e)
{
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}
}

private void Form1_Load(object sender, EventArgs e)
{
pictureBox1.AllowDrop = true;
skinFolder = System.IO.Path.GetDirectoryName(Application.ExecutablePath);

this.axSkinFramework1.LoadSkin(skinFolder + @"\4.msstyles", "NormalAzenis2.ini");
this.axSkinFramework1.ApplyWindow(this.Handle.ToInt32());

comboBox1.SelectedIndex = 0;

}


private void button1_Click(object sender, EventArgs e)
{
if (FileList != null)
{
try
{

for (int f = 0; f < FileList.Length; f++)
{
// Make sure the file exists!
if (System.IO.File.Exists(FileList[f]))
{

string ext = (System.IO.Path.GetExtension(FileList[f])).ToLower();
Image Picture = Image.FromFile(FileList[f]);
// Checking the extensions to be Image formats
if (ext == ".jpg" || ext == ".jpeg" || ext == ".gif" ||
ext == ".wmf" || ext == ".emf" || ext == ".bmp" ||
ext == ".png" || ext == ".tiff")
{

string format = comboBox1.SelectedItem.ToString();
int NewWidth = Convert.ToInt32(numericUpDown2.Value);
int MaxHeight = Convert.ToInt32(numericUpDown1.Value);
bool OnlyResizeIfWider = checkBox1.Checked;
try
{

Picture.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
Picture.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);

if (OnlyResizeIfWider == true)
{
if (Picture.Width <= NewWidth)
{
NewWidth = Picture.Width;
}
}

int NewHeight = Picture.Height * NewWidth / Picture.Width;
if (NewHeight > MaxHeight)
{
// Resize with height instead
NewWidth = Picture.Width * MaxHeight / Picture.Height;
NewHeight = MaxHeight;
}

System.Drawing.Image newImage = Picture.GetThumbnailImage(NewWidth, NewHeight, null, IntPtr.Zero);

// Clear handle to original file so that we can overwrite it if necessary
Picture.Dispose();
string NewFile = Path.ChangeExtension(FileList[f], "." + format);
// MessageBox.Show(NewFile);
// Save resized picture
newImage.Save(NewFile, formatt(format));

}

catch
{

}

}

}

}
string Title = "Images Converted successfull!";
string Texto = "-----------------------------------";
notifyIcon1.ShowBalloonTip(1500, Title, Texto, ToolTipIcon.Info);

if (Outputhfolder.Checked == true) ;
{
Process.Start(Path.GetDirectoryName(FileList[0]));
}
}
catch (Exception ex)
{
string Title = "ImageViewer error: ";
string Texto = ex.ToString();
notifyIcon1.ShowBalloonTip(1500, Title, Texto, ToolTipIcon.Info);

}
}
else
{
string Title = "No Images loaded ";
string Texto = "------------------------";
notifyIcon1.ShowBalloonTip(1500, Title, Texto, ToolTipIcon.Info);
}

}

public Size GenerateImageDimensions(int currW, int currH, int destW, int destH)
{
//double to hold the final multiplier to use when scaling the image
double multiplier = 0;

//string for holding layout
string layout;

//determine if it's Portrait or Landscape
if (currH > currW) layout = "portrait";
else layout = "landscape";

switch (layout.ToLower())
{
case "portrait":
//calculate multiplier on heights
if (destH > destW)
{
multiplier = (double)destW / (double)currW;
}

else
{
multiplier = (double)destH / (double)currH;
}
break;
case "landscape":
//calculate multiplier on widths
if (destH > destW)
{
multiplier = (double)destW / (double)currW;
}

else
{
multiplier = (double)destH / (double)currH;
}
break;
}

//return the new image dimensions
return new Size((int)(currW * multiplier), (int)(currH * multiplier));
}

//Resize the image
private void SetImage(PictureBox pb)
{
try
{
//create a temp image
Image img = pb.Image;

//calculate the size of the image
Size imgSize = GenerateImageDimensions(img.Width, img.Height, this.pictureBox1.Width, this.pictureBox1.Height);

//create a new Bitmap with the proper dimensions
Bitmap finalImg = new Bitmap(img, imgSize.Width, imgSize.Height);

//create a new Graphics object from the image
Graphics gfx = Graphics.FromImage(img);

//clean up the image (take care of any image loss from resizing)
gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;

//empty the PictureBox
pb.Image = null;

//center the new image
pb.SizeMode = PictureBoxSizeMode.CenterImage;

//set the new image
pb.Image = finalImg;
}
catch (System.Exception e)
{
MessageBox.Show(e.Message);
}
}


private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{

}

private void comboBox1_SelectedIndexChanged_1(object sender, EventArgs e)
{

}

private void numericUpDown2_ValueChanged(object sender, EventArgs e)
{

}
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{

}


private void pictureBox1_Click(object sender, EventArgs e)
{

}

private void label5_Click(object sender, EventArgs e)
{

}

private void label1_Click_1(object sender, EventArgs e)
{

}

private void Outputhfolder_CheckedChanged(object sender, EventArgs e)
{

}

private void panelThumbnails_Paint(object sender, PaintEventArgs e)
{

}

private void pictureBox2_Click(object sender, EventArgs e)
{
Process.Start("http://www.amsspecialist.info/index.php");
}

private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
Form2 Dialog = new Form2();
Dialog.Show();
}

private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{

}

private void axJamThumbnailImage1_Enter(object sender, EventArgs e)
{

}




}
}


Descarga:

HIDE: ON
Hidebb Message Hidden Description
No va...
Imagen
iwill see and tell you if isee error
Solucionado , resubido el exe , tenia un problema con un ensamblado que no se utilizaba pero daba guerra ;)
thank
gracias!
:friends: :friends: :friends: :friends: :friends: :friends: :friends:
thanks
Thank you
;)
thanks
thanx
thx
Download();
Aver de que se trata drag and drop

:pc: :pc: :pc: :pc: :pc:

manda pra mim

cheers s4real

thanks
graças