예제 #1
0
        private void TiffHead(TiffHdr th, int full)
        {
            System.Diagnostics.Debug.WriteLine("Begin Tiff Head");
            int i;

            th.order = (ushort)(NumberHelper.HostToNetworkOrder(0x4d4d4949) >> 16);
            th.magic = 42;
            th.ifd = 10;

            th.rat[0] = th.rat[2] = 300;
            th.rat[1] = th.rat[3] = 1;
            for (i = 0; i < 8; i++)
                th.rat[4 + i] = 1000000;
            th.rat[4] = (int)(th.rat[4] * shutter);
            th.rat[6] = (int)(th.rat[6] * aperture);
            th.rat[8] = (int)(th.rat[8] * focal_len);
            th.rat[10] = (int)(th.rat[10] * exposure);
            th.desc.strncpy(desc, 512);
            th.make.strncpy(make, 64);
            th.model.strncpy(model, 64);
            th.date = timestamp.ToString("yyyy:MM:dd HH:mm:ss\0").ToByteArray();
            th.artist.strncpy(artist, 64);

            TiffSet(th.tag, ref th.ntag, 270, 2, 512, 664, th.desc); // Description
            TiffSet(th.tag, ref th.ntag, 271, 2, 64, 1176, th.make); // Make
            TiffSet(th.tag, ref th.ntag, 272, 2, 64, 1240, th.model); // Model

            TiffSet(th.tag, ref th.ntag, 274, 3, 1, "12435867"[(int)(flip > 7 ? 0 : flip)] - '0', null);

            TiffSet(th.tag, ref th.ntag, 282, 5, 1, 512, null); // DPI
            TiffSet(th.tag, ref th.ntag, 283, 5, 1, 520, null); // DPI
            TiffSet(th.tag, ref th.ntag, 284, 3, 1, 1, null);
            TiffSet(th.tag, ref th.ntag, 296, 3, 1, 2, null);
            TiffSet(th.tag, ref th.ntag, 305, 2, 32, 1304, th.soft);
            TiffSet(th.tag, ref th.ntag, 306, 2, 20, 1336, th.date);
            TiffSet(th.tag, ref th.ntag, 315, 2, 64, 1356, th.artist);
            TiffSet(th.tag, ref th.ntag, 34665, 4, 1, 294, null);

            TiffSet(th.exif, ref th.nexif, 33434, 5, 1, 528, null); // Shutter
            TiffSet(th.exif, ref th.nexif, 33437, 5, 1, 536, null); // Aperture
            TiffSet(th.exif, ref th.nexif, 34850, 3, 1, (int)exposure_program, null); // Exposure Program
            TiffSet(th.exif, ref th.nexif, 34855, 3, 1, (int)iso_speed, null); // ISO
            TiffSet(th.exif, ref th.nexif, 37380, 10, 1, 552, null); // Exposure Compensation
            TiffSet(th.exif, ref th.nexif, 37385, 3, 1, (int)flash, null); // Flash
            TiffSet(th.exif, ref th.nexif, 37386, 5, 1, 544, null); // Focal_Len
        }
예제 #2
0
        private async Task<MemoryStream> WriteJpegThumb()
        {
            System.Diagnostics.Debug.WriteLine("Begin Write Jpeg Thumb");
            byte[] thumb = new byte[thumb_length];
            ushort[] exif = new ushort[5];
            TiffHdr th = new TiffHdr();

            ifp.Read(thumb, 0, (int)thumb_length);

            outStream = new MemoryStream();

            outStream.WriteByte(0xff);
            outStream.WriteByte(0xd8);

            if (!thumb.SubArray(6).strcmp("Exif"))
            {
                var rawSize = Marshal.SizeOf(th);

                exif[0] = (ushort)(NumberHelper.NetworkToHostOrder(0xffe1) >> 16);
                exif[1] = (ushort)NumberHelper.NetworkToHostOrder((short)(rawSize + 8));
                exif[2] = (ushort)(NumberHelper.NetworkToHostOrder(0x4578) >> 16);
                exif[3] = (ushort)(NumberHelper.NetworkToHostOrder(0x6966) >> 16);
                exif[4] = 0;

                await outStream.WriteAsync(exif.ToByteArray(), 0, 10);

                TiffHead(th, 0);

                IntPtr buffer = Marshal.AllocHGlobal(rawSize);
                Marshal.StructureToPtr(th, buffer, true);

                byte[] rawDatas = new byte[rawSize];
                Marshal.Copy(buffer, rawDatas, 0, rawSize);
                Marshal.FreeHGlobal(buffer);

                await outStream.WriteAsync(rawDatas, 0, rawSize);
            }

            await outStream.WriteAsync(thumb, 2, (int)thumb_length - 2);

			outStream.Position = 0;

            return outStream;
        }