I use LeadTools for scanning.
I want to convert scanning image to byte.
void twainSession_AcquirePage(object sender, TwainAcquirePageEventArgs e)
{
ScanImage = e.Image.Clone();
ImageSource source = RasterImageConverter.ConvertToSource(ScanImage, ConvertToSourceOptions.None);
}
How to convert ImageSource to Byte array?
I use use a MemoryStream:
Unless you explicitly need an ImageSource object, there's no need to convert to one. You can get a byte array containing the pixel data directly from Leadtools.RasterImage using this code:
Note that this gives you only the raw pixel data.
If you need a memory stream or byte array that contains a complete image such as JPEG, you also do not need to convert to source. You can use the Leadtools.RasterCodecs class like this:
I use this class to work with
Image
in WPFSo try different approaches and modernize this class as you need.
It seems that you can cast the result from .ConvertToSource to a BitmapSource instead of a ImageSource.
I am not 100% sure how this translate to your case but the doc from LeadTools show this VB sample:
I think it should be like
Then you can copy the BitmapSource pixels with BitmapSource.CopyPixels