Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 2 additions & 31 deletions android/src/main/java/com/wwimmo/imageeditor/ImageEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,32 +204,6 @@ public String getBase64(String format, boolean transparent, boolean includeImage
return Base64.encodeToString(byteArrayOS.toByteArray(), Base64.DEFAULT);
}

private String getMeasuredPosition(boolean cropToImageSize) {
MeasureToolEntity lastEntity = null;
for (int i = 0; i < mEntities.size(); i++) {
if (mEntities.get(i) instanceof MeasureToolEntity) {
lastEntity = (MeasureToolEntity) mEntities.get(i);
}
}
if (lastEntity != null) {
double scale = mBackgroundImage != null && cropToImageSize ? (double) mOriginalBitmapWidth / getWidth() : 1;
int pointsSize = lastEntity.getCurrentPoints().size();
int[][] positions = new int[pointsSize][];
for (int i = 0; i < pointsSize; i++) {
PointF position = lastEntity.getCurrentPoints().get(i);
int x = (int) (position.x * scale);
int y = (int) (position.y * scale);
positions[i] = new int[]{x, y};
}
Map exifPositionData = new HashMap();
exifPositionData.put("rmPoints", Arrays.deepToString(positions));
String result = exifPositionData.toString().replace("=", ":");
return result;
} else {
return null;
}
}

private Bitmap createImage(boolean transparent, boolean includeImage, boolean includeText, boolean cropToImageSize) {
Bitmap bitmap = Bitmap.createBitmap(
mBackgroundImage != null && cropToImageSize ? mOriginalBitmapWidth : getWidth(),
Expand Down Expand Up @@ -610,7 +584,7 @@ public void save(String format, String folder, String filename, boolean transpar
String path = createdFile.getPath();
this.onSaved(true, path);

this.updateExif(path, this.getMeasuredPosition(cropToImageSize));
this.updateExif(path);

success = true;
} catch (Exception e) {
Expand All @@ -630,15 +604,12 @@ public void save(String format, String folder, String filename, boolean transpar

}

public void updateExif(String path, String position) {
public void updateExif(String path) {
try {
File originalFile = new File(currentFilePath);

ExifInterface exif = new ExifInterface(path);
exif.setAttribute(ExifInterface.TAG_IMAGE_UNIQUE_ID, originalFile.getName());
if (position != null) {
exif.setAttribute(ExifInterface.TAG_USER_COMMENT, position);
}
exif.saveAttributes();
} catch (Exception e) {
Log.e("Update exif", "Failed to update exif!");
Expand Down
37 changes: 3 additions & 34 deletions ios/RNImageEditor/RNImageEditor/RNImageEditor.m
Original file line number Diff line number Diff line change
Expand Up @@ -558,33 +558,6 @@ - (UIImage*)createImageWithTransparentBackground: (BOOL) transparent includeImag
}
}

- (NSString*)getMeasuredPosition:(BOOL) cropToImageSize{
MeasurementEntity* lastEntity = nil;
for (MotionEntity* entity in self.motionEntities) {
if ([entity class] == [MeasurementEntity class]){
lastEntity = (MeasurementEntity *) entity;
}
}
if (lastEntity != nil) {
float scale = 1;
if (cropToImageSize == true) {
scale = _backgroundImage.size.width / self.bounds.size.width;
}
NSMutableArray* points = [lastEntity getPoints];
NSMutableArray* positions = [NSMutableArray new];
for (NSValue* value in points) {
CGPoint p = [value CGPointValue];
int x = p.x * scale;
int y = p.y * scale;
NSString* position = [NSString stringWithFormat:@"[%d, %d]",x,y];
[positions addObject:position];
}
NSString* result = [NSString stringWithFormat:@"{rmPoints:[%@]}",[positions componentsJoinedByString:@","]];
return result;
}
return nil;
}

- (void)saveImageOfType:(NSString*) type folder:(NSString*) folder filename:(NSString*) filename withTransparentBackground:(BOOL) transparent includeImage:(BOOL)includeImage includeText:(BOOL)includeText cropToImageSize:(BOOL)cropToImageSize {
UIImage *img = [self createImageWithTransparentBackground:transparent includeImage:includeImage includeText:(BOOL)includeText cropToImageSize:cropToImageSize];

Expand All @@ -598,8 +571,8 @@ - (void)saveImageOfType:(NSString*) type folder:(NSString*) folder filename:(NSS
if (error == nil) {
NSURL *fileURL = [[tempDir URLByAppendingPathComponent: filename] URLByAppendingPathExtension: type];
NSData *imageData = [self getImageData:img type:type];
NSString* measurementPosition = [self getMeasuredPosition:cropToImageSize];
[self saveImageWithMetadata:imageData fileURL:fileURL withMeasurementPosition:measurementPosition];

[self saveImageWithMetadata:imageData fileURL:fileURL];

if (_onChange) {
_onChange(@{ @"success": @YES, @"path": [fileURL path]});
Expand All @@ -617,7 +590,7 @@ - (void)saveImageOfType:(NSString*) type folder:(NSString*) folder filename:(NSS
}
}

- (void)saveImageWithMetadata:(NSData *)imageData fileURL:(NSURL*)fileURL withMeasurementPosition:(NSString*)measurementPosition
- (void)saveImageWithMetadata:(NSData *)imageData fileURL:(NSURL*)fileURL
{
NSString *originalFileName = [[_currentFilePath lastPathComponent] stringByDeletingPathExtension];
NSString *uniqueImageId = [self getUniqueImageId:originalFileName];
Expand All @@ -632,10 +605,6 @@ - (void)saveImageWithMetadata:(NSData *)imageData fileURL:(NSURL*)fileURL withMe

[mutableExifDict setValue:uniqueImageId forKey:(NSString *)kCGImagePropertyExifImageUniqueID];

if (measurementPosition != nil) {
[mutableExifDict setValue:measurementPosition forKey:(NSString *)kCGImagePropertyExifUserComment];
}

[mutableMetadataDict setObject:mutableExifDict forKey:(NSString *)kCGImagePropertyExifDictionary];

NSMutableData *destData = [NSMutableData data];
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "git",
"url": "https://github.com/hoverinc/react-native-sketch-image"
},
"version": "0.8.50",
"version": "0.8.51",
"description": "react-native-sketch-canvas allows you to draw / sketch on both iOS and Android devices and sync the drawing data between users. Of course you can save as image.",
"author": "Terry Lin, Thomas Steinbrüchel",
"main": "index.js",
Expand Down