InPlaceBitmapMetadataWriter.TrySave() returns true but does nothing

后端 未结 3 1563
生来不讨喜
生来不讨喜 2021-01-18 08:45

On some .JPG files (EPS previews, generated by Adobe Illustrator) in Windows 7 InPlaceBitmapMetadataWriter.TrySave() returns true after some SetQuery() calls, but does nothi

3条回答
  •  别那么骄傲
    2021-01-18 09:30

    Two things:

    1. I don't think you will be able to write to your metadata variable just like that, as it will be Frozen. So, you will have to clone it:

      BitmapMetadata metadata = frame.Metadata.Clone() as BitmapMetadata;
      
    2. Padding, you need padding. I found this out after about a day's worth of tinkering around trying to make some code (similar to yours) work. InPlaceBitmapMetadataWriter will not work if there is no metadata padding in your image file. So you need something like:

      JpegBitmapEncoder encoder = new JpegBitmapEncoder();
      if(frame != null && metadata != null) {
          metadata.SetQuery("/app1/ifd/PaddingSchema:Padding", padding);
          encoder.Frames.Add(BitmapFrame.Create(frame, frame.Thumbnail, metadata, frame.ColorContexts));
          using (Stream outputFile = File.Open(_myoutputpath, FileMode.Create, FileAccess.ReadWrite)) {
              encoder.Save(outputFile);
          }
      }
      

    Now you can use the file located at _myoutputpath which has added metadata padding for your InPlaceBitmapMetadataWriter operations.

    This article and attached code should help you out.

提交回复
热议问题