2014-04-23 3 views
0

은 내가 쓰기에 이미지를로드하려는 writablebitmap.I을 만들려고 해요하지만 (이미지하십시오에주의를) 작동하지 않습니다windowsphone에서 writablebitmap에 이미지를로드하는 방법은 무엇입니까?

var b = new WriteableBitmap(336, 336); 

     var background = new Canvas(); 
     background.Height = b.PixelHeight; 
     background.Width = b.PixelWidth; 
     background.Background = new SolidColorBrush(Colors.Red); 

     var canvas = new Grid(); 
     canvas.Width = b.PixelWidth; 
     canvas.Height = b.PixelHeight; 

     var textBlock = new TextBlock(); 
     textBlock.Text = "sample"; 
     textBlock.Margin = new Thickness(0, 150, 0, 0); 
     textBlock.Width = 336; 
     textBlock.Foreground = new SolidColorBrush(Colors.Blue); //color of the text on the Tile  
     textBlock.FontSize = 26; 

     canvas.Children.Add(textBlock); 

     Image img = new Image(); 
     img.Source = new BitmapImage(new Uri("Images/TileBgs/Medium/sun.png", UriKind.Relative)); 
     img.ImageOpened += (s, e) => 
     { 
      b.Render(background, null); 
      b.Render(img, null); 
      b.Render(canvas, null); 
      b.Invalidate(); //Draw bitmap 

      using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()) 
      { 
       using (IsolatedStorageFileStream imageStream = new IsolatedStorageFileStream("/Shared/ShellContent/myImage.jpg", System.IO.FileMode.Create, isf)) 
       { 
        b.SaveJpeg(imageStream, b.PixelWidth, b.PixelHeight, 0, 100); 
       } 
      } 
     }; 
: 여기 enter image description here

은 내 코드입니다

무엇이 잘못 되었나요 ??

+0

정의 : doesnt work ... – thumbmunkeys

+1

3 렌더링 호출이 의미가 없으며, 캔버스 만 렌더링합니다. – thumbmunkeys

답변

1
 var canvas = new Canvas(); 
     canvas.Width = 336; 
     canvas.Height = 336; 
     canvas.Background = new SolidColorBrush(Colors.Red); 
     var textBlock = new TextBlock(); 
     textBlock.Text = "sample"; 
     textBlock.Margin = new Thickness(130, 250, 0, 0); 
     textBlock.Width = 336; 
     textBlock.Foreground = new SolidColorBrush(Colors.Blue); 
     textBlock.FontSize = 26; 

     canvas.Children.Add(textBlock); 

     Image img = new Image(); 
     img.Source = new BitmapImage(new Uri("Images/TileBgs/Medium/sun.png", UriKind.Relative)); 
     img.Margin = new Thickness(40, 10, 0, 0); 
     img.Width = 250; 
     canvas.Children.Add(img); 
     Maingrid.Children.Add(canvas); 
관련 문제