微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

silverlight 获取取Media图片

界面:

<Grid x:Name="LayoutRoot" ShowGridLines="True" Background="White">
        <StackPanel Orientation="Horizontal" Margin="0,-117,0">
            <Border Width="320" Height="240"
                    Margin="5" BorderBrush="Black"
                    BorderThickness="1">
                    <MediaElement x:Name="media" Source="medias/may.wmv"/>
            </Border>
            
            <Border Width="160" Height="120"
                    Margin="5" BorderBrush="Black"
                    
                    BorderThickness="1">
                <Image x:Name="CaptureImage1" Stretch="None"/>
            </Border>
        </StackPanel>
        <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="10,10,0" Name="button1" VerticalAlignment="Top" Width="75" />
        <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="10,43,0" Name="button2" VerticalAlignment="Top" Width="75" />
    </Grid>

后台
  public MainPage()
        {
            InitializeComponent();
            button1.Click += new RoutedEventHandler(CaptureImage);
            button2.Click += new RoutedEventHandler(ModifyPixels);
        }

        private void CaptureImage(object sender,RoutedEventArgs e)
        { 
            //Transform to scale the image by 50%
            ScaleTransform transform = new ScaleTransform();
            transform.ScaleX = .5;
            transform.ScaleY = .5;
            
            //Get bitmap image from the current frame of video
            WriteableBitmap bitmap = new WriteableBitmap(media,transform);

            //Set the Image object,defined in XAML,to the new bitmap.
            CaptureImage1.source = bitmap;
        }

        private void ModifyPixels(object sender,RoutedEventArgs e)
        {
            //Get WriteableBitmap.
            if (CaptureImage1.source != null)
            {
                WriteableBitmap bitmap = new WriteableBitmap((BitmapSource)CaptureImage1.source);

                //Iterate through each pixel.
                for (int x = 0; x < bitmap.Pixels.Length; x++)
                { 
                    //Set every 4th pixel.
                    if (x % 4 == 0)
                    {
                        bitmap.Pixels[x] = 0;
                    }
                }

                //Set Image object,to the modified bitmap.
                CaptureImage1.source = bitmap;
            }
        }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐