我在C#dotnetcore中有一个AWS Lambda项目,我需要即时生成图像。
我尝试使用System.Drawing.Common
,但出现以下错误:
One or more errors occurred. (The type initializer for 'Gdip' threw an exception.)
然后我尝试使用MagickImage
,但出现错误:
"errorType": "MagickTypeErrorException",
"errorMessage": "UnableToReadFont `helvetica' @ error/annotate.c/RenderFreetype/1437",
这是我的代码:
public async Task<JsonResponse> FunctionHandler(string input, ILambdaContext context)
{
Stream stream = new MemoryStream();
using (MagickImage image = new MagickImage())
{
MagickReadSettings settings = new MagickReadSettings()
{
BackgroundColor = MagickColors.LightBlue, // -background lightblue
FillColor = MagickColors.Black, // -fill black
//Font = "Arial", // -font Arial
Width = 530, // -size 530x
Height = 175 // -size x175
};
image.Read("caption:This is a test.", settings); // caption:"This is a test."
image.Write(stream);// caption_long_en.png
}
}
关于如何从.NetCore创建映像的任何线索,并且该线索在AWS Lambda内均可使用。
感谢1