如果使用CGImageDestination在原始图像元数据中已经存在key/val,我似乎无法正确地将图像元数据写入图像.如果它们的key/val不存在于原始元数据中,它就可以正常工作.
几乎就像原始图像中的图像元数据属性优先于修改一样.这是我不知道的某种拜占庭格式问题,我需要以某种不寻常的方式填充键/ val,一个bug,还是?有人见过这个吗?
下面的代码和输出,适用于它正常工作的两种情况(如果值尚未设置)并且无法写入(如果该值已设置为其他值).
任何帮助表示非常感谢.
这是我在哪里/如何创建图像NSData:
// convert the existing asset to nsdata to overwrite itself
ALAssetRepresentation* rep = [asset defaultRepresentation];
Byte* buffer = (Byte*)malloc(rep.size);
NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:rep.size error:nil];
NSData* imageData = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];
// write the metadata directly into the nsdata of the image itself
NSData* newImage = [self writeMetadataIntoImageData:imageData metadata:newMetadata];
Run Code Online (Sandbox Code Playgroud)
以下是元数据的实际修改:
- (NSData*)writeMetadataIntoImageData:(NSData*)imageData metadata:(NSMutableDictionary*)metadataAsMutable
{
// create an imagesourceref
CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef) imageData, NULL);
// read and log pre write …Run Code Online (Sandbox Code Playgroud) 我有一个在Android 4.0及更高版本上开发的应用程序.(该应用不支持4.0以下的Android版本[Ice Cream Sandwich]).
该问题涉及(打印)各种图像(例如,jpeg或png)格式的DPI.
此问题与SCREEN DPI或各种Android设备的大小无关.它也与在屏幕尺寸上显示设备上的位图无关.
我使用以下代码在"位图"中加载图像文件.然后我一直在裁剪它并使用jpegCompression将其保存为JPEG格式的另一个文件.我已经能够通过以下代码执行此操作,但我无法获取加载的DPI或设置保存的图像文件的DPI.
所以我有两个问题.
1)如何在"Bitmap"中加载后,在JPEG文件中获取(打印)DPI?
2)在保存新生成的"位图"时,如何在JPEG文件中再次设置DPI?
以下是代码的一部分供参考.
FileInputStream inputStream = new FileInputStream(theSourcePhotoFilePathName);
Bitmap bitmap = null;
BitmapRegionDecoder decoder = null;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 1;
options.inDensity = 300; // Tried this but not working.
try {
decoder = BitmapRegionDecoder.newInstance(in, false);
bitmap = decoder.decodeRegion(region, options); // the region has cropping coordinates.
} catch (IllegalArgumentException e){
Log.d("First Activity", "Failed to recycle bitmap for rect=" + region, e);
} catch (IOException e) {
Log.d("First Activity", …Run Code Online (Sandbox Code Playgroud)