2013-06-05 31 views
5

Tôi đang sử dụng ExifLib tuyệt vời để trích xuất dữ liệu Exif từ hình ảnh của mình trên Windows Phone 8 (http://www.codeproject.com/Articles/36342/ExifLib-A-Fast-Exif-Data-Extractor-for-NET-2-0). Tuy nhiên, do hạn chế về quyền riêng tư, tôi cần có thể xóa dữ liệu GPS exif khỏi các hình ảnh được nhập từ thư viện ảnh của người dùng.Chỉnh sửa/Xóa dữ liệu hình ảnh Exif trên Windows Phone

Rất tiếc, tôi không thể tìm cách dễ dàng chỉnh sửa hoặc xóa dữ liệu này, bất kỳ con trỏ hoặc thư viện nào mà tôi bị thiếu?

Mọi trợ giúp sẽ được đánh giá cao.

Trả lời

4

Có một số blog post here cho biết cách xóa dữ liệu EXIF ​​mà không cần mã hóa lại hình ảnh. Mã từ bài đăng

using System.IO; 

namespace ExifRemover 
{ 
    public class JpegPatcher 
    { 
     public Stream PatchAwayExif(Stream inStream, Stream outStream) 
     { 
      byte[] jpegHeader = new byte[2]; 
      jpegHeader[0] = (byte)inStream.ReadByte(); 
      jpegHeader[1] = (byte)inStream.ReadByte(); 
      if (jpegHeader[0] == 0xff && jpegHeader[1] == 0xd8) //check if it's a jpeg file 
      { 
       SkipAppHeaderSection(inStream); 
      } 
      outStream.WriteByte(0xff); 
      outStream.WriteByte(0xd8); 

      int readCount; 
      byte[] readBuffer = new byte[4096]; 
      while ((readCount = inStream.Read(readBuffer, 0, readBuffer.Length)) > 0) 
       outStream.Write(readBuffer, 0, readCount); 

      return outStream; 
     } 

     private void SkipAppHeaderSection(Stream inStream) 
     { 
      byte[] header = new byte[2]; 
      header[0] = (byte)inStream.ReadByte(); 
      header[1] = (byte)inStream.ReadByte(); 

      while (header[0] == 0xff && (header[1] >= 0xe0 && header[1] <= 0xef)) 
      { 
       int exifLength = inStream.ReadByte(); 
       exifLength = exifLength << 8; 
       exifLength |= inStream.ReadByte(); 

       for (int i = 0; i < exifLength - 2; i++) 
       { 
        inStream.ReadByte(); 
       } 
       header[0] = (byte)inStream.ReadByte(); 
       header[1] = (byte)inStream.ReadByte(); 
      } 
      inStream.Position -= 2; //skip back two bytes 
     } 
    } 
} 
Các vấn đề liên quan