在Win2D API文档中,他们说
使用指定的文件名将整个位图保存到文件中 默认质量等级为0.9,CanvasBitmapFileFormat.Auto。
它没有说明文件的保存位置或如何选择文件的保存位置。 我尝试使用该方法来解决它,但每次我调用它时都会收到“拒绝访问”异常错误。
OUTER APPLY (
SELECT TOP 1
SUM(sin_TP013_Giorni) AS GiorniPianificatiAnno
, SUM(CASE
WHEN Ksin_TP013_IdArea = int_T013_IdArea THEN sin_TP013_Giorni
ELSE 0
END) AS GiorniPianificatiAnnoArea
FROM
Q_TP013_Pianificazione
INNER JOIN dbo.FN_DettaglioPianificazione(YEAR(@dataRiferimento), 0)
ON Progressivo = Ktyi_TP013_ProgressivoPian
WHERE
Ksin_TP013_AnnoRifPian = YEAR(@dataRiferimento)
AND Kint_TP013_IdAttivita = Kint_T041_IdAttivita
) AS Pianificazione
答案 0 :(得分:0)
首先,以上描述适用于CanvasBitmap.SaveAsync
方法。由于Win2D还包含CanvasImage
类,我建议避免将实例命名为CanvasImage
。
通常,由于UWP安全模型,您无法在用户的文件系统中传递路径(而不是像app包目录这样的特殊文件夹): https://docs.microsoft.com/en-us/windows/uwp/files/file-access-permissions
因此,您需要将流直接传递到SaveAsync
,而不仅仅是将路径作为字符串传递。在您的代码段中,您打开文件流但没有将流保存到文件中。只需将流保存到它将工作的文件。例如:
CanvasDevice device = CanvasDevice.GetSharedDevice();
CanvasRenderTarget renderTarget = new CanvasRenderTarget(device, 300, 300, 96);
using (var ds = renderTarget.CreateDrawingSession())
{
ds.Clear(Colors.White);
ds.DrawRectangle(155, 115, 80, 30, Colors.Black);
}
CanvasBitmap bit = renderTarget;
string filename = "Test pic test.png";
StorageFolder pictureFolder = KnownFolders.SavedPictures;
var file = await pictureFolder.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);
using (var fileStream = await file.OpenAsync(FileAccessMode.ReadWrite))
{
await bit.SaveAsync(fileStream, CanvasBitmapFileFormat.Png, 1f);
}
您可以参考this blog了解更多详情。