문제

이미지 파일에 드롭 그림자를 추가하고 싶습니다. 그렇게하는 가장 좋은 방법은 무엇입니까? WPF 이미지 컨트롤 생성 및 비트 맵 효과 추가에 대해 생각했지만 결과를 파일에 어떻게 저장할 수 있습니까?

감사합니다, 에릭

도움이 되었습니까?

해결책

rendertargetbitmap과 인코더를 사용하여이를 수행 할 수 있습니다. 인코더는 PNG, JPEG 등이 될 수 있습니다. 아래 코드 IMGControl은 이미지 컨트롤을 나타냅니다. 그러나 비트 맵 효과 이므로이 이미지를 그리드 내부에 넣고 Dropshadow와 동등한 다음 마진을 제공 한 다음 imgcontrol 대신 아래 코드의 그리드를 사용해야합니다.

double Height = imgControl.ActualHeight;
double Width = imgControl.ActualWidth;

RenderTargetBitmap bmp = new RenderTargetBitmap((int)Width, (int)Height, 
                                                96, 96, PixelFormats.Pbgra32);
bmp.Render(imgControl);

BitmapEncoder encoder = new JpegBitmapEncoder();

encoder.Frames.Add(BitmapFrame.Create(bmp));

using (Stream stream = File.Create("Yourfile.jpeg"))
{
    encoder.Save(stream);
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top