Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在C中向JPG图像添加页脚/EXIF(二进制数据)#_C#_.net_Jpeg_.net 4.5 - Fatal编程技术网

C# 在C中向JPG图像添加页脚/EXIF(二进制数据)#

C# 在C中向JPG图像添加页脚/EXIF(二进制数据)#,c#,.net,jpeg,.net-4.5,C#,.net,Jpeg,.net 4.5,大家好,我有一个图像,我想添加二进制数据作为该图像的页脚 RGBImage rgbImage = (RGBImage) RGBImage.LoadImage(@"test.tiff"); byte[] bytes = File.ReadAllBytes(@"C:\TEMP\gili.bin"); int padding =(int) Math.Ceiling((double)bytes.Length/(rgbImage.Width*3)); byte[] newMakerNoteImage =

大家好,我有一个图像,我想添加二进制数据作为该图像的页脚

RGBImage rgbImage =  (RGBImage) RGBImage.LoadImage(@"test.tiff");
byte[] bytes = File.ReadAllBytes(@"C:\TEMP\gili.bin");
int padding =(int) Math.Ceiling((double)bytes.Length/(rgbImage.Width*3));
byte[] newMakerNoteImage = new byte[rgbImage[0].Data.Length + (rgbImage.Width * 3 * padding)];
Buffer.BlockCopy(rgbImage[0].Data, 0, newMakerNoteImage, 0, rgbImage[0].Data.Length);
Buffer.BlockCopy(bytes, 0, newMakerNoteImage, rgbImage[0].Data.Length, bytes.Length);

BitmapPalette myPalette = BitmapPalettes.WebPalette;

           // Creates a new empty image with the pre-defined palette
           BitmapSource image = BitmapSource.Create(
               rgbImage.Width,
               rgbImage.Height,
               96,
               96,
               PixelFormats.Bgr24,
               myPalette,
               newMakerNoteImage,
               rgbImage.Width * 3);

           FileStream stream = new FileStream(@"C:\TEMP\new.jpg", FileMode.Create);
           JpegBitmapEncoder encoder = new JpegBitmapEncoder();
           encoder.FlipHorizontal = false;
           encoder.FlipVertical = false;
           encoder.QualityLevel = 30;
           encoder.Frames.Add(BitmapFrame.Create(image));
           encoder.Save(stream);
图像输出良好,但二进制数据未添加到图像末尾。 你能告诉我我做得对吗


我想我可能看错了,我需要使用EXIF将这个makernote数据添加到图像中。图像的用户不应看到数据

这是我为创建EXIF/MakerNote而测试的解决方案
据我所知,37500是EXIF中的makernote十六进制标记


我希望
BitmapSource.Create
只处理相关数据,而
JpegBitmapEncoder.Save
无论如何都会将其转换为不同的格式,因此如果这不起作用,我不会感到惊讶。调用
JpegBitmapEncoder.Save
?@PieterWitvoet后,您是否尝试将自定义数据添加到输出流中?我正在尝试解决这个问题,我想我需要使用类似EXIF的东西,因为宽度和高度定义了图像。我不想将这个二进制文件(makernote)作为页脚包含到图像中。
JpegBitmapEncoder
有一个
MetaData
属性,这可能有用吗?
 public void CreateMakerNoteJpgImage(byte[] makerNoteArray, string path)
        {
            BitmapPalette myPalette = BitmapPalettes.WebPalette;

            // Creates a new empty image with the pre-defined palette
            BitmapSource image = BitmapSource.Create(
                Width,
                Height,
                96,
                96,
                PixelFormats.Bgr24,
                myPalette,
                _channels[0].Data,
                Width * 3);

            FileStream stream = new FileStream(path, FileMode.Create);

            BitmapMetadata metadata = new BitmapMetadata("jpg");
            //adding makernote data into EXIF of the jpeg image
            metadata.SetQuery("/app1/ifd/exif:{uint=37500}", makerNoteArray);

            JpegBitmapEncoder encoder = new JpegBitmapEncoder();
            encoder.FlipHorizontal = false;
            encoder.FlipVertical = false;
            encoder.QualityLevel = 30;
            BitmapFrame frame = BitmapFrame.Create(image, null, metadata, null);
            encoder.Frames.Add(frame);
            encoder.Save(stream);
        }