Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[image_picker]fix load error when the image is BMP/HEIF/HEIC format #4665

Closed
wants to merge 12 commits into from
Closed
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
5 changes: 5 additions & 0 deletions packages/image_picker/image_picker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@

## 0.8.4+12

* iOS:support images with heic,heif,raw,tiff formats.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* iOS:support images with heic,heif,raw,tiff formats.
* Adds support for HEIC, HEIF, RAW, and TIFF formats on iOS.


## 0.8.4+11

* Fixes Activity leak.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 46;
objects = {

/* Begin PBXBuildFile section */
1E9937F227DE2EB50047F36B /* tiffImage.tiff in Resources */ = {isa = PBXBuildFile; fileRef = 1E9937EE27DE2EB50047F36B /* tiffImage.tiff */; };
1E9937F327DE2EB50047F36B /* tiffImage.tiff in Resources */ = {isa = PBXBuildFile; fileRef = 1E9937EE27DE2EB50047F36B /* tiffImage.tiff */; };
1E9937F427DE2EB50047F36B /* heicImage.heic in Resources */ = {isa = PBXBuildFile; fileRef = 1E9937EF27DE2EB50047F36B /* heicImage.heic */; };
1E9937F527DE2EB50047F36B /* heicImage.heic in Resources */ = {isa = PBXBuildFile; fileRef = 1E9937EF27DE2EB50047F36B /* heicImage.heic */; };
1E9937F627DE2EB50047F36B /* heifImage.heif in Resources */ = {isa = PBXBuildFile; fileRef = 1E9937F027DE2EB50047F36B /* heifImage.heif */; };
1E9937F727DE2EB50047F36B /* heifImage.heif in Resources */ = {isa = PBXBuildFile; fileRef = 1E9937F027DE2EB50047F36B /* heifImage.heif */; };
1E9937F827DE2EB50047F36B /* rawImage.raw in Resources */ = {isa = PBXBuildFile; fileRef = 1E9937F127DE2EB50047F36B /* rawImage.raw */; };
1E9937F927DE2EB50047F36B /* rawImage.raw in Resources */ = {isa = PBXBuildFile; fileRef = 1E9937F127DE2EB50047F36B /* rawImage.raw */; };
334733FC266813EE00DCC49E /* ImageUtilTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FC8F0ED229FB90B00C8D58F /* ImageUtilTests.m */; };
334733FD266813F100DCC49E /* MetaDataUtilTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 680049252280D736006DD6AB /* MetaDataUtilTests.m */; };
334733FE266813F400DCC49E /* PhotoAssetUtilTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 68F4B463228B3AB500C25614 /* PhotoAssetUtilTests.m */; };
Expand Down Expand Up @@ -65,6 +73,10 @@

/* Begin PBXFileReference section */
0C7B151765FD4249454C49AD /* Pods-RunnerTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-RunnerTests/Pods-RunnerTests.release.xcconfig"; sourceTree = "<group>"; };
1E9937EE27DE2EB50047F36B /* tiffImage.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = tiffImage.tiff; sourceTree = "<group>"; };
1E9937EF27DE2EB50047F36B /* heicImage.heic */ = {isa = PBXFileReference; lastKnownFileType = file; path = heicImage.heic; sourceTree = "<group>"; };
1E9937F027DE2EB50047F36B /* heifImage.heif */ = {isa = PBXFileReference; lastKnownFileType = file; path = heifImage.heif; sourceTree = "<group>"; };
1E9937F127DE2EB50047F36B /* rawImage.raw */ = {isa = PBXFileReference; lastKnownFileType = file; path = rawImage.raw; sourceTree = "<group>"; };
334733F22668136400DCC49E /* RunnerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RunnerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
334733F62668136400DCC49E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
35AE65F25E0B8C8214D8372B /* libPods-RunnerTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-RunnerTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -148,6 +160,10 @@
680049282280E33D006DD6AB /* TestImages */ = {
isa = PBXGroup;
children = (
1E9937EF27DE2EB50047F36B /* heicImage.heic */,
1E9937F027DE2EB50047F36B /* heifImage.heif */,
1E9937F127DE2EB50047F36B /* rawImage.raw */,
1E9937EE27DE2EB50047F36B /* tiffImage.tiff */,
86E9A88F272747B90017E6E0 /* webpImage.webp */,
9FC8F0E8229FA49E00C8D58F /* gifImage.gif */,
680049362280F2B8006DD6AB /* jpgImage.jpg */,
Expand Down Expand Up @@ -361,18 +377,26 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
1E9937F227DE2EB50047F36B /* tiffImage.tiff in Resources */,
1E9937F827DE2EB50047F36B /* rawImage.raw in Resources */,
1E9937F427DE2EB50047F36B /* heicImage.heic in Resources */,
86430DF9272D71E9002D9D6C /* gifImage.gif in Resources */,
86E9A894272754A30017E6E0 /* webpImage.webp in Resources */,
86E9A895272769130017E6E0 /* pngImage.png in Resources */,
86E9A896272769150017E6E0 /* jpgImage.jpg in Resources */,
1E9937F627DE2EB50047F36B /* heifImage.heif in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
6801C8342555D726009DAF8D /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
1E9937F927DE2EB50047F36B /* rawImage.raw in Resources */,
9FC8F0EC229FA68500C8D58F /* gifImage.gif in Resources */,
1E9937F327DE2EB50047F36B /* tiffImage.tiff in Resources */,
1E9937F527DE2EB50047F36B /* heicImage.heic in Resources */,
1E9937F727DE2EB50047F36B /* heifImage.heif in Resources */,
680049382280F2B9006DD6AB /* pngImage.png in Resources */,
680049392280F2B9006DD6AB /* jpgImage.jpg in Resources */,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,46 @@ - (void)testSaveGIFImage API_AVAILABLE(ios(14)) {
[self verifySavingImageWithPickerResult:result];
}

- (void)testSaveTIFFImage API_AVAILABLE(ios(14)) {
NSURL *imageURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"tiffImage"
withExtension:@"tiff"];
NSItemProvider *itemProvider = [[NSItemProvider alloc] initWithContentsOfURL:imageURL];
PHPickerResult *result = [self createPickerResultWithProvider:itemProvider
withIdentifier:UTTypeWebP.identifier];

[self verifySavingImageWithPickerResult:result];
}

- (void)testSaveHEICImage API_AVAILABLE(ios(14)) {
NSURL *imageURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"heicImage"
withExtension:@"heic"];
NSItemProvider *itemProvider = [[NSItemProvider alloc] initWithContentsOfURL:imageURL];
PHPickerResult *result = [self createPickerResultWithProvider:itemProvider
withIdentifier:UTTypeWebP.identifier];

[self verifySavingImageWithPickerResult:result];
}

- (void)testSaveHEIFImage API_AVAILABLE(ios(14)) {
NSURL *imageURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"heifImage"
withExtension:@"heif"];
NSItemProvider *itemProvider = [[NSItemProvider alloc] initWithContentsOfURL:imageURL];
PHPickerResult *result = [self createPickerResultWithProvider:itemProvider
withIdentifier:UTTypeWebP.identifier];

[self verifySavingImageWithPickerResult:result];
}

- (void)testSaveRAWImage API_AVAILABLE(ios(14)) {
NSURL *imageURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"rawImage"
withExtension:@"raw"];
NSItemProvider *itemProvider = [[NSItemProvider alloc] initWithContentsOfURL:imageURL];
PHPickerResult *result = [self createPickerResultWithProvider:itemProvider
withIdentifier:UTTypeWebP.identifier];

[self verifySavingImageWithPickerResult:result];
}

/**
* Creates a mock picker result using NSItemProvider.
*
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>

#import <UniformTypeIdentifiers/UTCoreTypes.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a blank line after it; they are different import sections.

#import "FLTPHPickerSaveImageToPathOperation.h"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please undo this change.

API_AVAILABLE(ios(14))
@interface FLTPHPickerSaveImageToPathOperation ()

Expand Down Expand Up @@ -84,16 +84,28 @@ - (void)start {
}
if (@available(iOS 14, *)) {
[self setExecuting:YES];

if ([self.result.itemProvider hasItemConformingToTypeIdentifier:UTTypeWebP.identifier]) {
[self.result.itemProvider
loadDataRepresentationForTypeIdentifier:UTTypeWebP.identifier
completionHandler:^(NSData *_Nullable data,
NSError *_Nullable error) {
UIImage *image = [[UIImage alloc] initWithData:data];
[self processImage:image];
}];
return;
NSArray *supportedRepresentations = @[
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Supported" seems misleading here; this isn't an exhaustive list since there's the other codepath as well. What is distinct about these vs other types that makes them need to use a different code path (so that we can name the list accordingly)?

UTTypeRAWImage.identifier,
UTTypeTIFF.identifier,
UTTypeBMP.identifier,
UTTypePNG.identifier,
UTTypeHEIF.identifier,
UTTypeHEIC.identifier,
UTTypeJPEG.identifier,
UTTypeWebP.identifier,
UTTypeGIF.identifier,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we changing the codepath for types that already worked? Is this a preferred API?

];
for (NSString *identifier in supportedRepresentations) {
if ([self.result.itemProvider hasItemConformingToTypeIdentifier:identifier]) {
[self.result.itemProvider
loadDataRepresentationForTypeIdentifier:identifier
completionHandler:^(NSData *_Nullable data,
NSError *_Nullable error) {
UIImage *image = [[UIImage alloc] initWithData:data];
[self processImage:image];
}];
return;
}
}

[self.result.itemProvider
Expand Down
2 changes: 1 addition & 1 deletion packages/image_picker/image_picker/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for selecting images from the Android and iOS image
library, and taking new pictures with the camera.
repository: https://github.com/flutter/plugins/tree/main/packages/image_picker/image_picker
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+image_picker%22
version: 0.8.4+11
version: 0.8.4+12

environment:
sdk: ">=2.14.0 <3.0.0"
Expand Down