getting there
This commit is contained in:
34
ImageConverter/Magick.cs
Normal file
34
ImageConverter/Magick.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace ImageConverter
|
||||
{
|
||||
public static class Magick
|
||||
{
|
||||
public static void FileConvert(String infile, String outfile)
|
||||
{
|
||||
ProcessStartInfo psi = new ProcessStartInfo("magick");
|
||||
psi.ArgumentList.Add(infile);
|
||||
psi.ArgumentList.Add(outfile);
|
||||
Process? p = Process.Start(psi);
|
||||
if (p==null)
|
||||
{
|
||||
throw new Exception("Could not launch magick");
|
||||
}
|
||||
p.WaitForExit();
|
||||
}
|
||||
|
||||
public static Byte[] BmpToJpg(this Byte[] bmpbuf)
|
||||
{
|
||||
String path = Path.GetTempFileName();
|
||||
String bmppath = Path.Combine(path, "magicktmp.bmp");
|
||||
String jpgpath = Path.Combine(path, "magicktmp.jpg");
|
||||
File.Delete(path);
|
||||
Directory.CreateDirectory(path);
|
||||
File.WriteAllBytes(bmppath, bmpbuf);
|
||||
FileConvert(bmppath, jpgpath);
|
||||
Byte[] buf = File.ReadAllBytes(jpgpath);
|
||||
Directory.Delete(path, true);
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user