gpt4 book ai didi

c# - 如何将 WicImagingBitmap 转换为 Gdi+ 位图或流?

转载 作者:太空宇宙 更新时间:2023-11-03 14:12:41 25 4
gpt4 key购买 nike

我是一名 .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);

谢谢,

最佳答案

以上是我的发现,希望对你有帮助。 http://www.leadtools.com/help/leadtools/v15/DH/Wpf/TO/Tutorial_Load.htm

关于c# - 如何将 WicImagingBitmap 转换为 Gdi+ 位图或流?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7344429/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com