如何将 WicImagingBitmap 转换为 Gdi+位图还是流?
我是一名 .net 开发人员,我正在使用 WindowsAPICodePackage WIC 来渲染图像。我想将 WIC ImagingBitmap 转换为 gdi+ 位图或 MemoryStream,而不是使用其自己的方法“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);
谢谢,
I'm a .net developer and I'm using WindowsAPICodePackage WIC to render images. I want to convert WIC ImagingBitmap to a gdi+ bitmap or to a MemoryStream instead using its own method "SaveToFile". Is there a way? Here is my code, please help:
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);
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我发现的,希望有帮助。
http://www.leadtools.com/help/leadtools /v15/DH/Wpf/TO/Tutorial_Load.htm
Here is what I found, hope it helps.
http://www.leadtools.com/help/leadtools/v15/DH/Wpf/TO/Tutorial_Load.htm