wp中的位图

        //
        // 摘要:
        //     使用提供的元素和变换初始化 System.Windows.Media.Imaging.WriteableBitmap 类的新实例。
        //
        // 参数:
        //   element:
        //     要在位图中呈现的所需元素。
        //
        //   transform:
        //     用户要在绘制到位图中之前的最后一步中应用到元素的变换。如果您希望位图将它的变换考虑在内,则这对于您特别有意义。此值可以为 null。
        //
        // 异常:
        //   System.ArgumentNullException:
        //     element 为 null。
        //
        //   System.ArgumentException:
        //     元素大小无效。当像素宽度或像素高度不大于零时,发生这种情况。
        [SecuritySafeCritical]
        public WriteableBitmap(UIElement element, Transform transform);
View Code

public WriteableBitmap(UIElement element, Transform transform);

将某元素通过变换,绘出其形状。 

获取照相机中的图片,进行重绘

void OnPhotoChooserCompleted(object sender, PhotoResult args)
        {
            if (args.Error != null || args.ChosenPhoto == null)
                return;

            BitmapImage bitmapImage = new BitmapImage();
            bitmapImage.SetSource(args.ChosenPhoto);

            Image imgBase = new Image();
            imgBase.Source = bitmapImage;
            imgBase.Stretch = Stretch.None;

            // Upper-left
            WriteableBitmap writeableBitmap = 
                new WriteableBitmap(bitmapImage.PixelWidth / 2,
                                    bitmapImage.PixelHeight / 2);
            writeableBitmap.Render(imgBase, null);
            writeableBitmap.Invalidate();
            imgUL.Source = writeableBitmap;

            // Upper-right
            writeableBitmap = new WriteableBitmap(bitmapImage.PixelWidth / 2,
                                                  bitmapImage.PixelHeight / 2);
            TranslateTransform translate = new TranslateTransform();
            translate.X = -bitmapImage.PixelWidth / 2;
            //在位图上呈现元素
            writeableBitmap.Render(imgBase, translate);
            //对位图进行重绘
            writeableBitmap.Invalidate();
            imgUR.Source = writeableBitmap;

            // Lower-left
            writeableBitmap = new WriteableBitmap(bitmapImage.PixelWidth / 2,
                                                  bitmapImage.PixelHeight / 2);
            translate.X = 0;
            translate.Y = -bitmapImage.PixelHeight / 2;
            writeableBitmap.Render(imgBase, translate);
            writeableBitmap.Invalidate();
            imgLL.Source = writeableBitmap;

            // Lower-right
            writeableBitmap = new WriteableBitmap(bitmapImage.PixelWidth / 2,
                                                  bitmapImage.PixelHeight / 2);
            translate.X = -bitmapImage.PixelWidth / 2;
            writeableBitmap.Render(imgBase, translate);
            writeableBitmap.Invalidate();
            imgLR.Source = writeableBitmap;

            txtblk.Visibility = Visibility.Collapsed;
        }

 

posted @ 2013-07-29 09:57  haiziguo  阅读(244)  评论(0编辑  收藏  举报