2012-04-09 1 views
0

하나의 큰 이미지를 만들기 위해 쓰기 가능한 비트 맵에 일부 텍스트와 이미지를 렌더링하려고합니다.이 방법은 이미지를 생성하거나 조작하기위한 다른 위치에서 작동했지만 어떤 이유로이 인스턴스는 검은 색 이미지 만 생성합니다. 만약 원본 이미지를 원본 WriteableBitmap으로 설정했다면 괜찮습니다.하지만 SaveJpeg를 호출 한 다음 LoadJpeg를 호출하면 이미지가 검은 색으로 표시됩니다 (예, 실제로 SaveJpeg를 호출해야하므로 섬기는 사람). 다음은 내가 요소를 렌더링하기 위해 노력하고있어 방법은 다음과 같습니다 SaveJpeg를 호출 할 때 그래서 분명히 WriteableBitmap 검은 색으로 배경을 투명하게 렌더링WriteableBitmap.SaveJpeg는 검은 색 이미지 (WP7)를 렌더링합니다.

NoteViewModel note = Instance.Note; 
var grid = new Grid() 
{ 
    Height = 929, 
    Width = 929 
}; 
grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(679) }); 
grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) }); 
var noteText = new TextBlock() 
{ 
    Text = note.Text, 
    FontFamily = note.FontFamily, 
    Foreground = note.FontColor, 
    TextWrapping = System.Windows.TextWrapping.Wrap, 
    Width = 929, 
    Height = 679 
}; 
Grid.SetRow(noteText, 0); 
grid.Children.Add(noteText); 

WriteableBitmap sigImage = Instance.Signature.SignatureImage; 
var sig = new Image() 
{ 
    Source = sigImage, 
    Height = 250, 
    Width = (sigImage.PixelWidth/sigImage.PixelHeight) * 250, 
    Margin = new Thickness(929 - ((sigImage.PixelWidth/sigImage.PixelHeight) * 250), 0, 0, 0) 
}; 
Grid.SetRow(sig, 1); 
grid.Children.Add(sig); 

var messagePicture = new WriteableBitmap(grid, null); 

var stream = new MemoryStream(); 

messagePicture.SaveJpeg(stream, messagePicture.PixelWidth, messagePicture.PixelHeight, 0, 100); //Save to a temp stream 

stream.Position = 0; 

var test = new WriteableBitmap(929,929); //Load the picture back up to see it 
test.LoadJpeg(stream); 

img.Source = test; //Show the image on screen (img is an Image element) 
+0

jpg 크기가 얼마나 큽니까? 100에서 95로 품질을 바꿀 수 있고 그것이 여전히 발생하는지 (100을 사용하지 않고 항상 항상 95를 사용하고 여러 곳에서 비슷한 코드를 사용하고 있기 때문에 묻기 만합니다.) –

+0

929 x 929이고 품질을 변경하지 마십시오. t 아무것도 수정하는 것. – Daniel

답변

1

을, 그래서 나는과 같이,뿐만 아니라 흰색 캔버스를 렌더링함으로써이 문제를 해결 :

var background = new Canvas() 
{ 
    Width = 929, 
    Height = 929, 
    Background = new SolidColorBrush(Colors.White) 
}; 

messagePicture.Render(background, new TranslateTransform()); 
+0

어떻게 WPF에서 이것을 달성 할 수 있는지 어떤 생각. –