2016-07-18 4 views
0

私はポリフォンオブジェクトをイメージに変換して最終的にpngファイルとして保存する必要があるWindows Phone 8.1アプリケーションで作業しています。今までは、さまざまなプロパティを持つポリゴンオブジェクトを作成しました。今私は他の部分については無知です。WIndows Phone 8.1のビットマップイメージにポリゴンオブジェクトを保存する

 pol.Opacity = 0.5; 
     System.Windows.Point Point1 = new System.Windows.Point(10, 200); 
     System.Windows.Point Point2 = new System.Windows.Point(60, 140); 
     System.Windows.Point Point3 = new System.Windows.Point(130, 140); 
     System.Windows.Point Point4 = new System.Windows.Point(180, 200); 
     System.Windows.Point Point5 = new System.Windows.Point(130, 260); 
     System.Windows.Point Point6 = new System.Windows.Point(60, 260); 
     PointCollection myPointCollection = new PointCollection(); 
     myPointCollection.Add(Point1); 
     myPointCollection.Add(Point2); 
     myPointCollection.Add(Point3); 
     myPointCollection.Add(Point4); 
     myPointCollection.Add(Point5); 
     myPointCollection.Add(Point6); 
     pol.Points = myPointCollection; 
     var imageBrush = new ImageBrush(); 
     imageBrush.ImageSource = image.Source; 
     pol.Fill = imageBrush; 
     pol.Height = image.Height; 
     pol.MaxHeight = image.Height; 
     pol.MaxWidth = image.Width; 
     pol.Width = image.Width; 
     pol.Stroke = new SolidColorBrush(Colors.Red); 
     pol.StrokeThickness = 2; 
     pol.Margin = image.Margin; 

答えて

1

これを実現するには、WritableBitmapクラスを使用できます。 Silverlightについては、How to Crop an Image based on a Shape or Path control?という類似の投稿があります。希望は、少なくともいくつかの基本的な概念を提供します。これについてさらに助けが必要な場合は、私に知らせてください。 PNGなどの形状を保存するには

+0

まさに...私も同じものを使っています。 – abhishek

+0

これは実際には機能しましたが、私が直面している新しい問題は、Windows Phone 8.1の「写真」にpngファイルとしてシェイプを保存していることです。 –

0

、あなたは次のコードスニペットを利用することができます

 WriteableBitmap bmp = GetAsWritableBitmap(); 
     using (var mediaLibrary = new MediaLibrary()) 
     { 
      using (var stream = new MemoryStream()) 
      { 
       var fileName = string.Format("Gs{0}.jpg", Guid.NewGuid()); 
       bmp.SaveJpeg(stream, bmp.PixelWidth, bmp.PixelHeight, 0, 100); 
       stream.Seek(0, SeekOrigin.Begin); 
       var picture = mediaLibrary.SavePicture(fileName, stream); 
       if (picture.Name.Contains(fileName)) return true; 
      } 
     } 

お役に立てば幸いです。

+0

あなたのために機能しましたか? –

関連する問題