The wpf control saves the content in the image format.

Source: Internet
Author: User

The wpf control saves the content in the image format.

The name of the wpf control is yellow!

// Save to a specific path
FileStream fs = new FileStream (@ "C: \ image.png", FileMode. Create );
// Convert an object to a bitmap
RenderTargetBitmap bmp = new RenderTargetBitmap (int) this. mediaElement1.ActualWidth, (int) this. mediaElement1.ActualHeight, 100,100, PixelFormats. Pbgra32 );
Bmp. Render (this. mediaElement1 );
// Encode the object set into an image stream
BitmapEncoder encoder = new PngBitmapEncoder ();
Encoder. Frames. Add (BitmapFrame. Create (bmp ));
// Save it to the path
Encoder. Save (fs );
// Release resources
Fs. Close ();
Fs. Dispose ();

 

// The second screenshot is full screen.

Image myImage = new Bitmap (Screen. PrimaryScreen. Bounds. Width, Screen. PrimaryScreen. Bounds. Height );
Graphics g = Graphics. FromImage (myImage );
G. copyFromScreen (new Point (0, 0), new Point (0, 0), new Size (Screen. primaryScreen. bounds. width, Screen. primaryScreen. bounds. height ));
IntPtr dc1 = g. GetHdc (); // the two statements are redundant here. For details, refer to the GetHdc () Definition.
G. ReleaseHdc (dc1 );
G. Dispose ();
MyImage. Save (@ "C: \ image.png", System. Drawing. Imaging. ImageFormat. Png );

Original Author http://blog.sina.com.cn/s/blog_8bf5ef0d01013wli.html


In VS2008 WPF, which of the following controls is used to display images saved in XML files? Image?

Image control. <ImageBrush ImageSource = "./icons/Bomber.png" TileMode = "Tile" Viewport = "0.3, 0.15,"/>

How does WPF set different image content in the Trigger of a template based on the control of the template?

I have provided ideas to do this without using triggers.
First, I wrote a class that inherits RadioButton. Two string fields are added to store the image paths in the RadioButton state.
Public class MyRadioButton: RadioButton
{
Public string EnableImaUri
{
Get {return (string) GetValue (EnableImaUriProperty );}
Set {SetValue (EnableImaUriProperty, value );}
}

Public static readonly DependencyProperty EnableImaUriProperty = DependencyProperty. Register ("EnableImaUri", typeof (string), typeof (MyRadioButton), null );
Public string DisEnableImaUri
{
Get {return (string) GetValue (DisEnableImaUriProperty );}
Set {SetValue (DisEnableImaUriProperty, value );}
}

Public static readonly DependencyProperty DisEnableImaUriProperty = DependencyProperty. Register ("DisEnableImaUri", typeof (string), typeof (MyRadioButton), null );
}
Then, put a button and radiobutton on the front end of the page. The idea is to change the source of the Image through the IsEnabledChanged event of radiobutton. Because this event is not triggered during the first loading, the image still needs to write the default path at the foreground.
<Local: MyRadioButton x: Name = "myRbtn1" EnableImaUri = "ranbo.jpg" DisEnableImaUri = "shafa.jpg" IsEnabledChanged = "myRbtn1_IsEnabledChanged">
<Image Width = "100" Height = "100" Source = "/WpfApplication1; component/Images/shafa.jpg"/>
</Local: MyRadioButton>

<Button Width = "50" Height = "20" Click = "Button_Click" Margin = "10 & quo ...... remaining full text>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.