当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET CroppedBitmap.BeginInit方法代码示例

本文整理汇总了VB.NET中System.Windows.Media.Imaging.CroppedBitmap.BeginInit方法的典型用法代码示例。如果您正苦于以下问题:VB.NET CroppedBitmap.BeginInit方法的具体用法?VB.NET CroppedBitmap.BeginInit怎么用?VB.NET CroppedBitmap.BeginInit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。


在下文中一共展示了CroppedBitmap.BeginInit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。

示例1: New

' 导入命名空间
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
开发者ID:VB.NET开发者,项目名称:System.Windows.Media.Imaging,代码行数:68,代码来源:CroppedBitmap.BeginInit


注:本文中的System.Windows.Media.Imaging.CroppedBitmap.BeginInit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。