Dll: ImageConvertResize

Plugins y todo lo relacionado para Autoplay Media Studio.
Hola compañeros , me he animado hacer una dll en c# después de ver el tutorial de pabloko ( gracias ) , la dll sirve para redimensionar y convertir de un formato a otro imagenes , la redimension mantiene una relaccion tamaño aspecto , osea que rstringe proporcines para no deformar la imagen , la llamada solo tiene una funcion:

ResizeConvertImage(string OriginalFile, string NewFile, int NewWidth, int MaxHeight, string format, int OnlyResizeIfWider)

string OriginalFile = archivo de salida
string NewFile = Archivo de destino , debemos proporcionar ruta completa nombre del archivo y nueva extensión en caso de cambio.
int NewWidth = Nuevo tamaño en anchura
int MaxHeight = la altura dependerá del ancho , podemos fijar un maximo pero entoces cambiara newwidth al valor que no deforme la imagen.
string format = Formato de salida de la imagen , formatos soportados : "Bmp","Emf","Exif","Gif","Ico","Jpeg","Png","Tiff","Wmf".
int OnlyResizeIfWider= valor 1 = solo redimensiona si es para mayor , 0 = redimensiona siempre.

Codigo fuente de la dll:
using System;
using System.Collections.Generic;
using System.Text;
using RGiesecke.DllExport;

namespace ImageConverResizer
{
internal static class UnmanagedExports
{
[DllExport("ResizeConvertImage", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
static void ResizeConvertImage(string OriginalFile, string NewFile, int NewWidth, int MaxHeight, string format, int OnlyResizeIfWider)
{
System.Drawing.Image Image = System.Drawing.Image.FromFile(OriginalFile);

// Prevent using images internal thumbnail
Image.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
Image.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);

if (OnlyResizeIfWider == 1)
{
if (Image.Width <= NewWidth)
{
NewWidth = Image.Width;
}
}

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

System.Drawing.Image newImage = Image.GetThumbnailImage(NewWidth, NewHeight, null, IntPtr.Zero);
var formatFile = System.Drawing.Imaging.ImageFormat.Bmp;
if (format == "Bmp") { formatFile = System.Drawing.Imaging.ImageFormat.Bmp; }
else if (format == "Emf") { formatFile = System.Drawing.Imaging.ImageFormat.Emf; }
else if (format == "Exif") { formatFile = System.Drawing.Imaging.ImageFormat.Exif; }
else if (format == "Gif") { formatFile = System.Drawing.Imaging.ImageFormat.Gif; }
else if (format == "Ico") { formatFile = System.Drawing.Imaging.ImageFormat.Icon; }
else if (format == "Jpeg") { formatFile = System.Drawing.Imaging.ImageFormat.Jpeg; }
else if (format == "Png") { formatFile = System.Drawing.Imaging.ImageFormat.Png; }
else if (format == "Tiff") { formatFile = System.Drawing.Imaging.ImageFormat.Tiff; }
else if (format == "Wmf") { formatFile = System.Drawing.Imaging.ImageFormat.Wmf; }
// Clear handle to original file so that we can overwrite it if necessary
Image.Dispose();

// Save resized picture
newImage.Save(NewFile,formatFile);
}

}
}


Es la primera vez que hago algo con C# y gracias a que pabloko nos lo pone fácil , así que supongo que el código tendrá mejoras y errores para parar un carro ( alguna vez hay que empezar) , espero vuestros comentarios y sugerencias , saludos

Descarga:

HIDE: ON
Hidebb Message Hidden Description
jejejejeje ya te dige que era muy facil ;) genial trabajo!
There is one thing you did forget you are only changing he image w/h the file as not really been changed tho as you not also included resolution maybe that could be a update for the future :)
patch escribió:There is one thing you did forget you are only changing he image w/h the file as not really been changed tho as you not also included resolution maybe that could be a update for the future :)
My experience in C # is 0, if you fix some script I'd like to see it to improve the dll, Greetings
excelente trabajo amigo sin duda todos se están animando a hacer dll haber cuando me entra a mi la fiebre de las dll, por los momentos solo tengo la de usarlas nada mas ejejejje.

La usare en mi proyecto haber como anda y si encuentro algo interesante o no interesante te avisare en cuanto la use.
using System;
using System.Collections.Generic;
using System.Text;
using RGiesecke.DllExport;

namespace ImageConverResizer
{
internal static class UnmanagedExports
{
[DllExport("ResizeConvertImage", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
static void ResizeConvertImage(string OriginalFile, string NewFile, int NewWidth, int MaxHeight, string format, int OnlyResizeIfWider)
{
System.Drawing.Image Image = System.Drawing.Image.FromFile(OriginalFile);

// Prevent using images internal thumbnail
Image.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
Image.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);

if (OnlyResizeIfWider == 1)
{
if (Image.Width <= NewWidth)
{
NewWidth = Image.Width;
}
}

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

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

// Clear handle to original file so that we can overwrite it if necessary
Image.Dispose();

// Save resized picture
newImage.Save(NewFile, formatt(format));
}

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 "Exif":
return System.Drawing.Imaging.ImageFormat.Exif;
case "Gif":
return System.Drawing.Imaging.ImageFormat.Gif;
case "Icon":
return System.Drawing.Imaging.ImageFormat.Icon;
case "Jpeg":
return System.Drawing.Imaging.ImageFormat.Jpeg;
case "MemoryBmp":
return System.Drawing.Imaging.ImageFormat.MemoryBmp;
case "Png":
return System.Drawing.Imaging.ImageFormat.Png;
case "Tiff":
return System.Drawing.Imaging.ImageFormat.Tiff;
case "Wmf":
return System.Drawing.Imaging.ImageFormat.Wmf;
default:
return System.Drawing.Imaging.ImageFormat.Jpeg;
}
}

}
}


problem solved
Special work

:yes: :yes: :yes:
grcias<div>
</div>
Pabloko escribió:
using System;
using System.Collections.Generic;
using System.Text;
using RGiesecke.DllExport;

namespace ImageConverResizer
{
internal static class UnmanagedExports
{
[DllExport("ResizeConvertImage", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
static void ResizeConvertImage(string OriginalFile, string NewFile, int NewWidth, int MaxHeight, string format, int OnlyResizeIfWider)
{
System.Drawing.Image Image = System.Drawing.Image.FromFile(OriginalFile);

// Prevent using images internal thumbnail
Image.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
Image.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);

if (OnlyResizeIfWider == 1)
{
if (Image.Width <= NewWidth)
{
NewWidth = Image.Width;
}
}

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

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

// Clear handle to original file so that we can overwrite it if necessary
Image.Dispose();

// Save resized picture
newImage.Save(NewFile, formatt(format));
}

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 "Exif":
return System.Drawing.Imaging.ImageFormat.Exif;
case "Gif":
return System.Drawing.Imaging.ImageFormat.Gif;
case "Icon":
return System.Drawing.Imaging.ImageFormat.Icon;
case "Jpeg":
return System.Drawing.Imaging.ImageFormat.Jpeg;
case "MemoryBmp":
return System.Drawing.Imaging.ImageFormat.MemoryBmp;
case "Png":
return System.Drawing.Imaging.ImageFormat.Png;
case "Tiff":
return System.Drawing.Imaging.ImageFormat.Tiff;
case "Wmf":
return System.Drawing.Imaging.ImageFormat.Wmf;
default:
return System.Drawing.Imaging.ImageFormat.Jpeg;
}
}

}
}


problem solved
Gracias makina , actualizo la dll ;)
I am also bad at C# so sadly lua is my language and I still not as good as some but I do try hard :)
sexy enchufe XD
oh. thanks
gracias
excelente dll, pero que te parece si agregas una opción mas una de rencionar la imagen estirándola totalmente sin que conserve su aspecto original
thank
thanks
thanks
Thank you
Gracias!
good functions