Share via


CroppedBitmap.EndInit 메서드

정의

CroppedBitmap 초기화가 끝났음을 나타냅니다.

public:
 virtual void EndInit();
[System.Security.SecurityCritical]
public void EndInit ();
public void EndInit ();
[<System.Security.SecurityCritical>]
abstract member EndInit : unit -> unit
override this.EndInit : unit -> unit
abstract member EndInit : unit -> unit
override this.EndInit : unit -> unit
Public Sub EndInit ()

구현

특성

예외

Source 속성은 null입니다.

또는 먼저 EndInit()를 호출하지 않고 BeginInit() 메서드를 호출한 경우

예제

다음 예제에서는 초기화 하는 방법을 보여 줍니다는 CroppedBitmap 집합을 사용 하 여 속성을 사용 하 여 합니다 BeginInitEndInit 메서드.

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace SDKSample
{
    public partial class CroppedBitmapExample : Page
    {
        public CroppedBitmapExample()
        {

            ///// Create a BitmapImage and set it's DecodePixelWidth to 200. Use  /////
            ///// this BitmapImage as a source for other BitmapSource objects.    /////

            BitmapImage myBitmapImage = new BitmapImage();

            // BitmapSource objects like BitmapImage can only have their properties
            // changed within a BeginInit/EndInit block.
            myBitmapImage.BeginInit();
            myBitmapImage.UriSource = new Uri(@"sampleImages/WaterLilies.jpg",UriKind.Relative);

            // To save significant application memory, set the DecodePixelWidth or  
            // DecodePixelHeight of the BitmapImage value of the image source to the desired 
            // height or width of the rendered image. If you don't do this, the application will 
            // cache the image as though it were rendered as its normal size rather then just 
            // the size that is displayed.
            // Note: In order to preserve aspect ratio, set DecodePixelWidth
            // or DecodePixelHeight but not both.
            myBitmapImage.DecodePixelWidth = 200;
            myBitmapImage.EndInit();

            ////////// Crop the BitmapSource ////////////
            // Use the BitmapImage created above as the source for a new BitmapSource object
            // which is cropped.                                               
            // Note: New BitmapSource does not cache. It is always pulled when required.

            CroppedBitmap myCroppedBitmap = new CroppedBitmap();

            // BitmapSource objects like CroppedBitmap can only have their properties
            // changed within a BeginInit/EndInit block.
            myCroppedBitmap.BeginInit();

            // Use the BitmapSource object defined above as the source for this new 
            // BitmapSource (chain the BitmapSource objects together).
            myCroppedBitmap.Source = myBitmapImage;

            // Crop the image to the rectangular area defined below. 
            // The image is cropped to 80 pixels less in width and 60 less 
            // in height then the original source.
            myCroppedBitmap.SourceRect = new Int32Rect(0,0,(int)myBitmapImage.Width-80, (int)myBitmapImage.Height-60);
            myCroppedBitmap.EndInit();

            // Create Image Element
            Image myImage = new Image();
            myImage.Width = 200;
            //set image source
            myImage.Source = myCroppedBitmap;

            // Add Image to the UI
            StackPanel myStackPanel = new StackPanel();
            myStackPanel.Children.Add(myImage);
            this.Content = myStackPanel;
        }
    }
}
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Media
Imports System.Windows.Media.Imaging

Namespace SDKSample

    Class CroppedBitmapExample
        Inherits Page

        Public Sub New()

            '/// Create a BitmapImage and set it's DecodePixelWidth to 200. Use  /////
            '/// this BitmapImage as a source for other BitmapSource objects.    /////
            Dim myBitmapImage As New BitmapImage()

            ' BitmapSource objects like BitmapImage can only have their properties
            ' changed within a BeginInit/EndInit block.
            myBitmapImage.BeginInit()
            myBitmapImage.UriSource = New Uri("sampleImages/WaterLilies.jpg", UriKind.Relative)

            ' To save significant application memory, set the DecodePixelWidth or  
            ' DecodePixelHeight of the BitmapImage value of the image source to the desired 
            ' height or width of the rendered image. If you don't do this, the application will 
            ' cache the image as though it were rendered as its normal size rather then just 
            ' the size that is displayed.
            ' Note: In order to preserve aspect ratio, set DecodePixelWidth
            ' or DecodePixelHeight but not both.
            myBitmapImage.DecodePixelWidth = 200
            myBitmapImage.EndInit()

            '//////// Crop the BitmapSource ////////////
            ' Use the BitmapImage created above as the source for a new BitmapSource object
            ' which is cropped.                                               
            ' Note: New BitmapSource does not cache. It is always pulled when required.
            Dim myCroppedBitmap As New CroppedBitmap()

            ' BitmapSource objects like CroppedBitmap can only have their properties
            ' changed within a BeginInit/EndInit block.
            myCroppedBitmap.BeginInit()

            ' Use the BitmapSource object defined above as the source for this new 
            ' BitmapSource (chain the BitmapSource objects together).
            myCroppedBitmap.Source = myBitmapImage

            ' Crop the image to the rectangular area defined below. 
            ' The image is cropped to 80 pixels less in width and 60 less 
            ' in height then the original source.
            myCroppedBitmap.SourceRect = New Int32Rect(0, 0, _
                CType(myBitmapImage.Width - 80, Integer), _
                CType(myBitmapImage.Height - 60, Integer))
            myCroppedBitmap.EndInit()

            ' Create Image Element
            Dim myImage As New Image()
            myImage.Width = 200
            'set image source
            myImage.Source = myCroppedBitmap

            ' Add Image to the UI
            Dim myStackPanel As New StackPanel()
            myStackPanel.Children.Add(myImage)
            Me.Content = myStackPanel

        End Sub
    End Class
End Namespace 'ImagingSnippetGallery

설명

간의 속성 초기화를 수행 해야 BeginInitEndInit 호출 합니다. 한 번의 CroppedBitmap 되었습니다 초기화 속성 변경은 무시 됩니다.

적용 대상

추가 정보