当前位置: 代码迷 >> Windows Mobile >> 为何图片加载不出来
  详细解决方案

为何图片加载不出来

热度:95   发布时间:2016-04-25 07:16:18.0
为什么图片加载不出来?
分裂图片--一张照片放进BitmapImage里面然后利用WriteableBitmap将图片分成4块

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Image Name="imgUL" Grid.Row="0" Grid.Column="0" Margin="2"/>
            <Image Name="imgUR" Grid.Row="0" Grid.Column="1" Margin="2"/>
            <Image Name="imgLL" Grid.Row="1" Grid.Column="0" Margin="2"/>
            <Image Name="imgLR" Grid.Row="1" Grid.Column="1" Margin="2"/>
        </Grid>




 int picturewidth;
        int pictureheight;
        public MainPage()
        {
            InitializeComponent();
            picturewidth =((int)ContentPanel.ActualWidth)- 8;
            pictureheight = ((int)ContentPanel.ActualHeight) - 8;
            // 用于本地化 ApplicationBar 的示例代码
            //BuildLocalizedApplicationBar();
            
        }

        protected override void OnManipulationStarted(ManipulationStartedEventArgs args)
        {
            BitmapImage bitmapImage = new BitmapImage(new Uri("/Images/123.png", UriKind.Relative));
            bitmapImage.DecodePixelHeight = pictureheight;
            bitmapImage.DecodePixelWidth = picturewidth;
            Image imgBase = new Image();
            imgBase.Source = bitmapImage; 
            imgBase.Stretch = Stretch.None;
            WriteableBitmap writeableBitmap = new WriteableBitmap(bitmapImage.PixelWidth / 2, bitmapImage.PixelHeight / 2);
            writeableBitmap.Render(imgBase, null);
            writeableBitmap.Invalidate();
            imgUL.Source = writeableBitmap;
            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;
            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;
  相关解决方案