add gps info to image
-
hi guys i write gps info into image but not display whats problem
private void button1_Click(object sender, EventArgs e) { Image Pic; PropertyItem[] PropertyItems; string FilenameTemp; System.Drawing.Imaging.Encoder Enc = System.Drawing.Imaging.Encoder.Transformation; EncoderParameters EncParms = new EncoderParameters(1); EncoderParameter EncParm; ImageCodecInfo CodecInfo = GetEncoderInfo("image/jpeg"); double dLat = 38.00000000000; double dLong = 48.0000000000; string Filename = "E:\\001.jpg"; byte[] bLat = BitConverter.GetBytes(dLat); byte[] bLong = BitConverter.GetBytes(dLong); Pic = Image.FromFile(Filename); PropertyItems = Pic.PropertyItems; PropertyItems[0].Id = 0x0002; PropertyItems[0].Type = 5; PropertyItems[0].Len = bLong.Length; PropertyItems[0].Value = bLong; Pic.SetPropertyItem(PropertyItems[0]); PropertyItems = Pic.PropertyItems; PropertyItems[0].Id = 0x0004; PropertyItems[0].Type = 5; PropertyItems[0].Len = bLat.Length; PropertyItems[0].Value = bLat; Pic.SetPropertyItem(PropertyItems[0]); FilenameTemp = Filename + ".temp"; EncParm = new EncoderParameter(Enc, (long)EncoderValue.TransformRotate90); EncParms.Param[0] = EncParm; Pic.Save("e:\\0001.jpg", CodecInfo, EncParms); } private static ImageCodecInfo GetEncoderInfo(String mimeType) { int j; ImageCodecInfo[] encoders; encoders = ImageCodecInfo.GetImageEncoders(); for (j = 0; j < encoders.Length; ++j) { if (encoders[j].MimeType == mimeType) return encoders[j]; } return null; }
thanks a lot -
hi guys i write gps info into image but not display whats problem
private void button1_Click(object sender, EventArgs e) { Image Pic; PropertyItem[] PropertyItems; string FilenameTemp; System.Drawing.Imaging.Encoder Enc = System.Drawing.Imaging.Encoder.Transformation; EncoderParameters EncParms = new EncoderParameters(1); EncoderParameter EncParm; ImageCodecInfo CodecInfo = GetEncoderInfo("image/jpeg"); double dLat = 38.00000000000; double dLong = 48.0000000000; string Filename = "E:\\001.jpg"; byte[] bLat = BitConverter.GetBytes(dLat); byte[] bLong = BitConverter.GetBytes(dLong); Pic = Image.FromFile(Filename); PropertyItems = Pic.PropertyItems; PropertyItems[0].Id = 0x0002; PropertyItems[0].Type = 5; PropertyItems[0].Len = bLong.Length; PropertyItems[0].Value = bLong; Pic.SetPropertyItem(PropertyItems[0]); PropertyItems = Pic.PropertyItems; PropertyItems[0].Id = 0x0004; PropertyItems[0].Type = 5; PropertyItems[0].Len = bLat.Length; PropertyItems[0].Value = bLat; Pic.SetPropertyItem(PropertyItems[0]); FilenameTemp = Filename + ".temp"; EncParm = new EncoderParameter(Enc, (long)EncoderValue.TransformRotate90); EncParms.Param[0] = EncParm; Pic.Save("e:\\0001.jpg", CodecInfo, EncParms); } private static ImageCodecInfo GetEncoderInfo(String mimeType) { int j; ImageCodecInfo[] encoders; encoders = ImageCodecInfo.GetImageEncoders(); for (j = 0; j < encoders.Length; ++j) { if (encoders[j].MimeType == mimeType) return encoders[j]; } return null; }
thanks a lotThere is an article on an Exif library here on CodeProject: ExifLibrary for .NET[^] Perhaps that might help you - I had to change some code for updating GPS values, but according to the author that should already be fixed now.