UWP BitmapEncoder SetProperties is not supported
UWP BitmapEncoder SetProperties is not supported
所以我正在创建一个UWP应用程序,需要将文本和图像写入图像文件并保存。我目前已经使用这个源代码在C++中创建了一个D2D包装器,然后是一个C#包装器,它只允许您用漂亮的C#代码访问C++类的函数(它只访问WINMD C++包装器)。
然而,在我们将图像和文本写入流后,我们需要能够使用EXIF头保存文件,其中包含关于旋转和位置的信息。
我们使用encoder.BitmapProperties.SetPropertiesAsync
来实现这一点,但它返回:
Exception thrown: 'System.Exception' in Tester.exe
Additional information: The operation is unsupported. (Exception from HRESULT: 0x88982F81)
没有内部异常,堆栈跟踪为:
at Windows.Graphics.Imaging.BitmapEncoder.get_BitmapProperties()
at Tester.ViewModels.<_SaveImageWithPropertiesAsync>d__56.MoveNext()
我想尽量避免手动添加头,因为我担心D2DContext返回的流不包含任何头信息或其他信息,所以它无法向其添加任何内容。
这是我代码的相关部分:
C++
再次,你可以在这里找到原始来源
IRandomAccessStream^ D2DWrapper::EndDraw()
{
DX::ThrowIfFailed(
m_d2dContext->EndDraw()
);
// If needPreview is true, we return a valid IRandomAccessStream reference.
GUID wicFormat = GUID_ContainerFormatBmp;
ComPtr<IStream> stream;
ComPtr<ISequentialStream> ss;
auto inMemStream = ref new InMemoryRandomAccessStream();
DX::ThrowIfFailed(
CreateStreamOverRandomAccessStream(inMemStream, IID_PPV_ARGS(&stream))
);
SaveBitmapToStream(m_targetBitmap, m_wicFactory, m_d2dContext, wicFormat, stream.Get());
return inMemStream;
}
C#包装
public IRandomAccessStream EndDraw() {
return _context.EndDraw()
}
C#测试仪
async Task _SaveImageWithPropertiesAsync(UWPImaging.Image image, PhotoOrientation photoOrientation)
{
var ras = await image.EndDraw();
var decoder = await BitmapDecoder.CreateAsync(ras);
var file = await KnownFolders.PicturesLibrary.CreateFileAsync(
"test.jpeg",
CreationCollisionOption.GenerateUniqueName);
using (var outputStream = await file.OpenAsync(FileAccessMode.ReadWrite))
{
var encoder = await BitmapEncoder.CreateForTranscodingAsync(outputStream, decoder);
var properties = new BitmapPropertySet { { "System.Photo.Orientation", new BitmapTypedValue(photoOrientation, PropertyType.UInt16) } };
await encoder.BitmapProperties.SetPropertiesAsync(properties); // This is where the error occurs
await encoder.FlushAsync();
}
}
如果能为我们提供帮助,我们将不胜感激!
谢谢,
诺兰
如果目标容器不同(例如JPEG到TIFF),则需要根据目标容器规范在写入元数据之前对其进行修改。WIC资源管理器可以帮助您了解文件的元数据结构。我发现一些编解码器(例如HEIF)在尝试获取所有可用元数据时会冻结应用程序,因此最好手动选择需要的内容。
相关文章:
- OpenMP卸载说'fatal error: could not find accel/nvptx-none/mkoffload'
- 使用JsonCpp将数据返回到带有pybind11的python会在python调用中产生Symbol not foun
- OpenCV Android C++ imwrite not found
- 应用程序崩溃并显示"symbol _ZdlPvm, version Qt_5 not defined in file libQt5Core.so.5 with link time reference"
- MATLAB to C++: csvread() not supported by MATLAB Coder
- 如何修复 SDL2 "GLSL 3.30 is not supported"错误
- 在 OpenGL 中在 Mac 上编译着色器时出现"version not supported"错误
- C++ GLSL 着色器:"error: GLSL 3.30 is not supported. Supported versions are: 1.10, 1.20, 1.30, 1.00 ES,
- CUDA 错误:"dynamic initialization is not supported for __device__, __constant__ and __shared__ variabl
- MAC OpenGL 着色器错误:"version '150' is not supported "
- C++ 使用 Curl 库编程 - 抛出错误"protocol https not supported or disabled."
- C/C++ getnameinfo ai_family not supported
- UWP BitmapEncoder SetProperties is not supported
- PTXAS 在结构数组上使用 thrust::sort 时"double is not supported"警告
- nullptr_type not supported by simple_type_specifier
- NodeJS Addon Unordered_map not supported?
- 结构成员顺序导致"non-trivial designated initializers not supported"错误
- QTcpServer->listen() on WinCE6 "protocol type not supported"
- OpenCV- 使用 cvProjectPoints2 时的"Homogeneous coordinates are not supported"
- 英特尔C++编译器给出"offload constructs are not supported on this platform"错误