android - error on editing metadata org.apache.sanselan.ImageReadException: Couldn't read magic numbers to guess format -
i have video capture , video gallery image trying add custom metadata using sanselan library in android have got org.apache.sanselan.imagereadexception: couldn't read magic numbers guess exception.i have tried everywhere didnt solution.please me
this did
file storagedirectory = environment.getexternalstoragepublicdirectory(environment.directory_pictures); file image = file.createtempfile(imagefilename, ".jpg", storagedirectory); imagefilelocation = image.getabsolutepath(); file dst = file.createtempfile(imagefilename, ".jpg", storagedirectory); try { new testgps().changeexifmetadata(image, dst); system.out.println("data has been changed successfull!"); imagefilelocation = dst.getabsolutepath();
testgps.java
public class testgps { double db=0.3; /** * example illustrates how add/update exif metadata in jpeg file. * * @param jpegimagefile source image file. * @param dst output file. * @throws ioexception * @throws imagereadexception * @throws imagewriteexception */ public void changeexifmetadata(file jpegimagefile, file dst) throws ioexception, imagereadexception, imagewriteexception { outputstream os = null; try { tiffoutputset outputset = null; // note metadata might null if no metadata found. iimagemetadata metadata = sanselan.getmetadata(jpegimagefile); jpegimagemetadata jpegmetadata = (jpegimagemetadata) metadata; if (null != jpegmetadata) { // note exif might null if no exif metadata found. tiffimagemetadata exif = jpegmetadata.getexif(); if (null != exif) { // tiffimagemetadata class immutable (read-only). // tiffoutputset class represents exif data write. // // usually, want update existing exif metadata // changing // values of few fields, or adding field. // in these cases, easiest use getoutputset() // start "copy" of fields read image. outputset = exif.getoutputset(); } } // if file not contain exif metadata, create empty // set of exif metadata. otherwise, keep of other // existing tags. if (null == outputset) outputset = new tiffoutputset(); { // example of how add field/tag output set. // // note should first remove field/tag if // exists in directory, or may end duplicate // tags. see above. // // fields/tags expected in exif directories; // others can occur in more 1 directory (and have // different meaning in different directories). // // taginfo constants contain description of // directories associated given tag. // // see // org.apache.sanselan.formats.tiff.constants.alltagconstants // tiffoutputfield aperture = tiffoutputfield.create( tiffconstants.exif_tag_aperture_value, outputset.byteorder, new double(db)); tiffoutputdirectory exifdirectory = outputset .getorcreateexifdirectory(); // make sure remove old value if present (this method // not fail if tag not exist). exifdirectory.removefield(tiffconstants.exif_tag_aperture_value); exifdirectory.add(aperture); } { // example of how add/update gps info output set. // new york city double longitude = -74.0; // 74 degrees w (in degrees east) double latitude = 40 + 43 / 60.0; // 40 degrees n (in degrees // north) outputset.setgpsindegrees(longitude, latitude); } // printtagvalue(jpegmetadata, tiffconstants.tiff_tag_date_time); //os = new fileoutputstream(dst); new exifrewriter().updateexifmetadatalossless(jpegimagefile, os, outputset); os.close(); os = null; } { if (os != null) try { os.close(); } catch (ioexception e) { } } } }
Comments
Post a Comment