OneNote API创建显示红色x的图像
本文关键字:图像 红色 显示 API 创建 OneNote | 更新日期: 2023-09-27 18:16:05
尝试使用Windows Store示例将图像捕获到OneNote API被证明有点困难。
我得到一个"红色x"而不是图像。它看起来像图像源是不正确的,但我做了一些改变。
下面是我的代码:(任何帮助都会很感激)
private async void btnCreatePage_Click(object sender, RoutedEventArgs e)
{
await CreatePageWithImage();
}
private async Task CreatePageWithImage()
{
var client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
if (IsAuthenticated)
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authClient.Session.AccessToken);
}
const string imagePartName = "assets''Asthma.jpg";
string date = GetDate();
string simpleHtml = "<html>" +
"<head>" +
"<title>A simple page created with an image on it</title>" +
"<meta name='"created'" content='"" + date + "'" />" +
"</head>" +
"<body>" +
"<h1>This is a page with an ximage on it</h1>" +
"<img src='"name:" + imagePartName + "'" alt='"A beautiful logo'" width='"426'" height='"68'" />" +
"</body>" +
"</html>";
// Create the image part - make sure it is disposed after we've sent the message in order to close the stream.
HttpResponseMessage response;
using (var imageContent = new StreamContent(await GetBinaryStream("assets''Asthma.jpg")))
{
imageContent.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
HttpRequestMessage createMessage = new HttpRequestMessage(HttpMethod.Post, PagesEndPoint)
{
Content = new MultipartFormDataContent
{
{new StringContent(simpleHtml, System.Text.Encoding.UTF8, "text/html"), "Presentation"},
{imageContent, imagePartName}
}
};
// Must send the request within the using block, or the image stream will have been disposed.
response = await client.SendAsync(createMessage);
}
tbResponse.Text = response.ToString();
}
在代码中,您已将媒体类型设置为"image/jpg"。应该将其设置为"image/jpeg"。您还需要更改imagePartName以删除"'"。
—James (@jmslau)