I have a one note sample where I tried to extract image from One Note, write it to a file, then construct a new Image object to take in that written file and append back to one note file and save the document. I found that image before and after vary vastly on its’ size.
Here is a snippet of my code:
Document doc = new Document(file);
var images = doc.GetChildNodes();
foreach(Image image in images)
{
if(image.ParentNode is Page)
{
page = image.ParentNode as Page;
using(var outStream = new FileStream(imageFile, FileMode.Create, FileAccess.ReadWrite, FileShare.Read))
outStream.Write(image.Bytes, 0, image.Bytes.Length);
var newImage = new Image(imageFile)
{
Height = image.Height,
Width = image.Width,
HorizontalOffset = image.HorizontalOffset,
VerticalOffset = image.VerticalOffset,
Alignment = image.Alignment,
AlternativeTextDescription = image.AlternativeTextDescription,
AlternativeTextTitle = image.AlternativeTextTitle,
IsBackground = image.IsBackground,
HyperlinkUrl = image.HyperlinkUrl
};
page.AppendChildFirst(newImage);
page.RemoveChild(image);
}
else if(image.ParentNode is OutlineElement)
{
outline = image.ParentNode as OutlineElement;
using(var outStream = new FileStream(imageFile, FileMode.Create, FileAccess.ReadWrite, FileShare.Read))
outStream.Write(image.Bytes, 0, image.Bytes.Length);
var newImage = new Image(imageFile)
{
Height = image.Height,
Width = image.Width,
HorizontalOffset = image.HorizontalOffset,
VerticalOffset = image.VerticalOffset,
Alignment = image.Alignment,
AlternativeTextDescription = image.AlternativeTextDescription,
AlternativeTextTitle = image.AlternativeTextTitle,
IsBackground = image.IsBackground,
HyperlinkUrl = image.HyperlinkUrl
};
outline.AppendChildFirst(newImage);
outline.RemoveChild(image);
}
}
Sample: mixed_objects.zip - Google Drive