2016-09-22 30 views
0

我開發了一個應用程序,其中使用了文本塊。現在我要刪除的影子上的文字,如給定的圖像對文本塊中的文本投下陰影

enter image description here

我用模糊的效果,但它給錯誤。

private async void ok_Click(object sender, RoutedEventArgs e) 
{ 
    br = new Border(); 
    Word_art obvwa = new Word_art(); 
    if (txtbox.Text == "") 
    { 
     var line = new MessageDialog("PLease enter the text"); 
     await line.ShowAsync(); 
    } 
    else 
    { 
     TB1 = new TextBlock(); 
     TB1.FontSize = txtbox.FontSize; 
     TB1.Foreground = txtbox.Foreground; 

     SolidColorBrush sb = new SolidColorBrush(); 
     var color = sb.Color; 

     TB1.Opacity = 60;     
     TB1.Text = txtbox.Text; 
     var blur = new GaussianBlurEffect(); 
     blur.BlurAmount = 5.0f; 
     blur.Source = TB1.Text; 
     var sitem = stylecombo.SelectedItem as ComboBoxItem; 
     string sitemfm = Convert.ToString(sitem.Content); 
     FontFamily fm = new FontFamily(""+ sitemfm); 
     TB1.FontFamily = fm; 

我試過Microsoft.graphics.effect程序集,但它不包含在我的項目中。

+0

它給出了什麼錯誤,你的代碼是什麼樣的,你試過了什麼? –

+0

var blur = new GaussianBlurEffect(); blur.BlurAmount = 5.0f; blur.Source = bitmap; –

+0

它給缺少的庫或程序集參考 –

回答

1

要創建帶有上述陰影的textblock,您可以使用包裝陰影控件的WindowsUIDevLabs庫。您只需配置陰影的OffsetXOffsetY屬性即可生效。類似的代碼如下:

<Page 
... 
xmlns:common="using:SamplesCommon" > 

    <common:CompositionShadow 
     x:Name="shadowcontrol" 
     HorizontalAlignment="Center" 
     VerticalAlignment="Center" 
     BlurRadius="5" 
     OffsetX="-1" 
     OffsetY="-1" 
     ShadowOpacity=".7" 
     Color="Green">  
     <TextBlock 
      Foreground="#6B0F02" 
      FontSize="48" 
      TextWrapping="Wrap"> 
      Lorem ipsum dolor sit amet. 
     </TextBlock>   
    </common:CompositionShadow> 

而結果:

enter image description here

而對於如何使用WindowsUIDevLabs,請下載包和SamplesCommon項目添加到您的解決方案,加參考你的項目。您也可以直接在包裝內運行樣品進行進一步測試。