-I am trying to write a method for a Card Scanner and I am quite new in C#
:)
-The application I wrote can scan and gets the images from the Scanner, but I can not show them on the WPF
.
-The SDK
is written for Windows Forms
, so I have to do a conversion from Bitmap
to BitmapImage
(What I actually did).
-When I try to add a Source with XAML
, it works, but it should get the Source from the Memory! But I have no Idea how it supposed to be on C#
Please help! I´ve tried almost everything. Thank you
class StartScan
{
protected internal SDKWrapper sdk = new SDKWrapper();
MainWindow mw;
public void Scan()
{
try
{
ShowImage(sdk.ScanAndGetImage(), false);
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
private void ShowImage(System.Drawing.Image image, bool converted)
{
mw = new MainWindow();
if (image == null)
{
System.Console.WriteLine("IMAGE=NULL");
return;
}
int displayW =(int) mw.CardBoxRect.Width;
int displayH = (int) mw.CardBoxRect.Height;
Bitmap b = new Bitmap(displayW,displayH);
mw.CardBox.Source = BitmapToImageSource(b);
}
BitmapImage BitmapToImageSource(Bitmap bitmap)
{
using (MemoryStream memory = new MemoryStream())
{
System.Console.WriteLine(bitmap.ToString());
bitmap.Save(memory, ImageFormat.Bmp);
memory.Position = 0;
BitmapImage bitmapimage = new BitmapImage();
bitmapimage.BeginInit();
bitmapimage.StreamSource = memory;
bitmapimage.CacheOption = BitmapCacheOption.OnLoad;
bitmapimage.EndInit();
bitmapimage.Freeze();
return bitmapimage;
}
}
}