Skip to content

Commit 0f79940

Browse files
committed
Use cgImage
1 parent e10f5ca commit 0f79940

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,8 +1740,9 @@ - (void)buildDataTransferItems:(std::vector<DataTransferItem> &)dataTransferItem
17401740

17411741
if ([MIMETypeString hasPrefix:@"image/"]) {
17421742
NSImage *image = [[NSImage alloc] initWithContentsOfURL:fileURL];
1743-
transferItem.width = static_cast<int>(image.size.width);
1744-
transferItem.height = static_cast<int>(image.size.height);
1743+
CGImageRef cgImage = [image CGImageForProposedRect:nil context:nil hints:nil];
1744+
transferItem.width = static_cast<int>(CGImageGetWidth(cgImage));
1745+
transferItem.height = static_cast<int>(CGImageGetHeight(cgImage));
17451746
}
17461747

17471748
dataTransferItems.push_back(transferItem);
@@ -1753,6 +1754,7 @@ - (void)buildDataTransferItems:(std::vector<DataTransferItem> &)dataTransferItem
17531754
NSString *MIMETypeString = imageType == NSPasteboardTypePNG ? @"image/png" : @"image/tiff";
17541755
NSData *imageData = [pasteboard dataForType:imageType];
17551756
NSImage *image = [[NSImage alloc] initWithData:imageData];
1757+
CGImageRef cgImage = [image CGImageForProposedRect:nil context:nil hints:nil];
17561758

17571759
NSString *dataURLString = RCTDataURL(MIMETypeString, imageData).absoluteString;
17581760

@@ -1761,8 +1763,8 @@ - (void)buildDataTransferItems:(std::vector<DataTransferItem> &)dataTransferItem
17611763
.type = MIMETypeString ? MIMETypeString.UTF8String : "",
17621764
.uri = dataURLString ? dataURLString.UTF8String : "",
17631765
.size = static_cast<int>(imageData.length),
1764-
.width = static_cast<int>(image.size.width),
1765-
.height = static_cast<int>(image.size.height),
1766+
.width = static_cast<int>(CGImageGetWidth(cgImage)),
1767+
.height = static_cast<int>(CGImageGetHeight(cgImage)),
17661768
};
17671769

17681770
dataTransferItems.push_back(transferItem);

0 commit comments

Comments
 (0)