Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wpf - Can i use System.Drawing in wpf?

i am saving the image in database. .. but how to retrieve that image from database .. when i try to use system.drawing .. it shows an error .. some of ppl saying i can't use system.drwaing in wpf .. not even dll file ..

my code is

private void btnShow_Click(object sender, RoutedEventArgs e)
{
       DataTable dt2 =  reqBll.SelectImage().Tables[0];
       byte[] data = (byte[])dt2.Rows[0][1];
       MemoryStream strm = new MemoryStream();
       strm.Write(data, 0, data.Length);
       strm.Position = 0;
       System.Drawing.Image img = System.Drawing.Image.FromStream(strm);
       BitmapImage bi = new BitmapImage();
       bi.BeginInit();
       MemoryStream ms = new MemoryStream();
       img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
       ms.Seek(0, SeekOrigin.Begin);
       bi.StreamSource = ms;
       bi.EndInit();
       ImgBox.Source = bi;
    }

what to do now?

i used the system.drawing.dll .. now i can use system.drawing.bitmap .. but after using it shows an error at System.Drawing.Image.FromStream(strm);

error:- argument exception was unhandled by user code

Parameter is not valid.

like image 975
omkar patade Avatar asked May 19 '12 06:05

omkar patade


People also ask

What is a viewbox in WPF?

The view box control is a WPF control belongs to the System. Windows. Controls namespace. It is used to stretch and scale a given control. The view box could only have one child; else if a view box contains more than one child, an argument exception will be thrown.

Is WPF front end or backend?

WPF, stands for Windows Presentation Foundation is a development framework and a sub-system of . NET Framework. WPF is used to build Windows client applications that run on Windows operating system. WPF uses XAML as its frontend language and C# as its backend languages.

How do you draw a line in WPF?

To draw a line, create a Line element. Use its X1 and Y1 properties to set its start point; and use its X2 and Y2 properties to set its end point. Finally, set its Stroke and StrokeThickness because a line without a stroke is invisible. Setting the Fill element for a line has no effect, because a line has no interior.

How do I add an image box in WPF?

Answers. If the PictureBox is missing from the Toolbox of a Windows Form application, right click in the Toolbox and select "Choose Items" to add it. For WPF, use the Image control.


1 Answers

You can use the classes in the System.Drawing namespace, but you will have to add a reference to the assembly containing the class you're interested in, by right clicking on the project, and choosing the "Add Reference..." option

like image 142
Rowland Shaw Avatar answered Sep 23 '22 14:09

Rowland Shaw