2010-08-16 5 views
0

WPF 응용 프로그램의 기존 BitmapSource 객체에 선 (또는 기하학적 모양)을 그립니다. 가장 좋은 방법은 무엇입니까?WPF에서 기존 BitmapSource에 선을 그리는 방법은 무엇입니까?

BitmapSource는 BitmapSource.Create (...) 호출의 결과입니다.

감사

  • 로맹 그 위에 빨간색 선으로 BitmapSource는에서 생성 된 이미지를 표시합니다 샘플 아래
+0

당신이 에서 보일 수 있습니다 구입하고 싶은 것을 확실하지 http://msdn.microsoft.com/en-us/ library/system.windows.media.imaging.writeablebitmap.aspx –

답변

0

. 그것이 당신이 성취하고자하는 것입니까?

XAML :

<Window x:Class="WpfApplication.Window1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="Window1" Height="300" Width="300"> 
    <Grid Background="LightBlue"> 
     <Image Source="{Binding Path=ImageSource}" /> 
     <Line 
      Stroke="Red" StrokeThickness="10" 
      X1="0" 
      Y1="0" 
      X2="{Binding Path=ActualWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}}}" 
      Y2="{Binding Path=ActualHeight, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}}}" /> 
    </Grid> 
</Window> 

코드 숨김

using System; 
using System.Windows; 
using System.Windows.Media; 
using System.Windows.Media.Imaging; 

namespace WpfApplication 
{ 
    public partial class Window1 : Window 
    { 
     public Window1() 
     { 
      InitializeComponent(); 

      DataContext = this; 
     } 

     public BitmapSource ImageSource 
     { 
      get 
      { 
       PixelFormat pf = PixelFormats.Bgr32; 
       int width = 200; 
       int height = 200; 
       int rawStride = (width * pf.BitsPerPixel + 7)/8; 
       byte[] rawImage = new byte[rawStride * height]; 

       Random value = new Random(); 
       value.NextBytes(rawImage); 

       return BitmapSource.Create(width, height, 96, 96, pf, null, rawImage, rawStride); 
      } 
     } 
    } 
} 
+0

프로그래머 답변 해 주셔서 감사합니다. 사실 저는 BitmapSource에 직접 쓰려고합니다. 그런 다음 나중에 BitmapSource의 내용을 다른 버퍼 나 파일에 저장할 수 있습니다! – HW2015

관련 문제