質問

私は.NET開発者であり、WICを使用して画像をレンダリングしています。 WIC ImagingBitMapをGDI+ BitMapに変換するか、独自のメソッド「SavetOfile」を使用してメモリストリームに変換したいと考えています。方法はありますか?これが私のコードです、助けてください:

int width = 256;
int height = 256;

D2DFactory d2DFactory = D2DFactory.CreateFactory(D2DFactoryType.SingleThreaded);
RenderTargetProperties renderTargetProperties = new RenderTargetProperties
{
    PixelFormat = new PixelFormat(Format.B8G8R8A8UNorm, AlphaMode.Premultiplied),
    Usage = RenderTargetUsages.GdiCompatible,
    RenderTargetType = RenderTargetType.Software
};

ImagingFactory wicFactory = ImagingFactory.Create();
ImagingBitmap imagingBitmap = wicFactory.CreateImagingBitmap((uint)width
    , (uint)height, Microsoft.WindowsAPICodePack.DirectX.WindowsImagingComponent.PixelFormats.Pbgra32Bpp, BitmapCreateCacheOption.CacheOnLoad);

RenderTarget renderTarget = d2DFactory.CreateWicBitmapRenderTarget(imagingBitmap, renderTargetProperties);
renderTarget.BeginDraw();

Random r = new Random();
for (int i = 0; i < 10; i++)
{
    renderTarget.DrawLine(new Point2F(r.Next(0, width), r.Next(0, height)), new Point2F(r.Next(0, width), r.Next(0, height))
        , renderTarget.CreateSolidColorBrush(new ColorF(1, 1, 0)), 4);
}
renderTarget.EndDraw();

string imageFilePath = @"c:\wic.png";
imagingBitmap.SaveToFile(wicFactory, ContainerFormats.Png, imageFilePath);

ありがとう、

役に立ちましたか?

解決

これが私が見つけたものです、それが役立つことを願っています。http://www.leadtools.com/help/leadtools/v15/dh/wpf/to/tutorial_load.htm

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top