I am using Lead Tool with c#. And Got error in below code. I pass this string base64String value from JS when I cropped Image and then convert it in c# in to Image with Base64ToImage function. So this is all complete code which I did.
private static Image Base64ToImage(string base64String)
{
Image img = null;
// Convert Base64 String to byte[]
byte[] imageBytes = Convert.FromBase64String(base64String);
using (MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length))
{
// Convert byte[] to Image
ms.Write(imageBytes, 0, imageBytes.Length);
img = System.Drawing.Image.FromStream(ms);
}
return img;
}
public static void CropImage(string base64String)
{
Image img = Base64ToImage(base64String);
using (MemoryStream ms = new MemoryStream())
{
img.Save(ms, ImageFormat.Bmp);
ms.Seek(0, System.IO.SeekOrigin.Begin);
using (RasterCodecs codecs = new RasterCodecs())
{
// Load the source image from disk
using (RasterImage image = codecs.Load(ms))
{
// Crop 100 pixels from each side of the image
CropCommand command = new CropCommand();
command.Rectangle = new LeadRect(
left,
top,
width,
height);
command.Run(image);
// Save it to disk
codecs.Save(image, output, RasterImageFormat.Bmp, 24);
}
}
}
}
An unhandled exception of type 'Leadtools.RasterException' occurred in Leadtools.Codecs.dll
Anyone please give my some solution for this.