Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
react-native-syan-image-picker
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenSource
react-native-syan-image-picker
Commits
bc2fe84f
Commit
bc2fe84f
authored
Aug 02, 2019
by
jearyVon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加支持保留png透明度的方法
parent
98e93870
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
2 deletions
+33
-2
RNSyanImagePicker.m
ios/RNSyanImagePicker.m
+33
-2
No files found.
ios/RNSyanImagePicker.m
View file @
bc2fe84f
...
@@ -280,10 +280,13 @@ RCT_EXPORT_METHOD(openVideoPicker:(NSDictionary *)options callback:(RCTResponseS
...
@@ -280,10 +280,13 @@ RCT_EXPORT_METHOD(openVideoPicker:(NSDictionary *)options callback:(RCTResponseS
NSMutableArray
*
selectedPhotos
=
[
NSMutableArray
array
];
NSMutableArray
*
selectedPhotos
=
[
NSMutableArray
array
];
[
weakPicker
showProgressHUD
];
[
weakPicker
showProgressHUD
];
if
(
imageCount
==
1
&&
isCrop
)
{
if
(
imageCount
==
1
&&
isCrop
)
{
[
selectedPhotos
addObject
:[
self
handleImageData
:
photos
[
0
]
quality
:
quality
]];
//增加png保留透明度功能
[
selectedPhotos
addObject
:[
self
handleImageData
:
photos
[
0
]
info
:
infos
[
0
]
quality
:
quality
]];
}
else
{
}
else
{
[
infos
enumerateObjectsUsingBlock
:
^
(
NSDictionary
*
_Nonnull
obj
,
NSUInteger
idx
,
BOOL
*
_Nonnull
stop
)
{
[
infos
enumerateObjectsUsingBlock
:
^
(
NSDictionary
*
_Nonnull
obj
,
NSUInteger
idx
,
BOOL
*
_Nonnull
stop
)
{
[
selectedPhotos
addObject
:[
self
handleImageData
:
photos
[
idx
]
quality
:
quality
]];
//增加png保留透明度功能
[
selectedPhotos
addObject
:[
self
handleImageData
:
photos
[
idx
]
info
:
infos
[
idx
]
quality
:
quality
]];
}];
}];
}
}
[
self
invokeSuccessWithResult
:
selectedPhotos
];
[
self
invokeSuccessWithResult
:
selectedPhotos
];
...
@@ -414,6 +417,34 @@ RCT_EXPORT_METHOD(openVideoPicker:(NSDictionary *)options callback:(RCTResponseS
...
@@ -414,6 +417,34 @@ RCT_EXPORT_METHOD(openVideoPicker:(NSDictionary *)options callback:(RCTResponseS
}
}
}
}
/**
保留png透明度的回调方法
通过文件后缀判断是否是png
*/
-
(
NSDictionary
*
)
handleImageData
:
(
UIImage
*
)
image
info
:
(
NSDictionary
*
)
info
quality
:
(
NSInteger
)
quality
{
NSMutableDictionary
*
photo
=
[
NSMutableDictionary
dictionary
];
NSString
*
filePath
=
[
NSString
stringWithFormat
:
@"%@"
,
info
[
@"PHImageFileURLKey"
]];
NSRange
range
=
[[
filePath
lowercaseString
]
rangeOfString
:
@".png"
];
BOOL
isPng
=
range
.
length
>
0
?
YES
:
NO
;
NSLog
(
@"++%@"
,
isPng
?
@"is png"
:
@"not png"
);
// 建议增加配置项选择是否放弃png透明度 提高压缩率
if
(
isPng
==
NO
){
return
[
self
handleImageData
:
image
quality
:
quality
];
}
NSData
*
imageData
=
UIImagePNGRepresentation
(
image
);
//无需压缩 所以不需要保存临时文件直接返回原图地址 ?????
photo
[
@"uri"
]
=
filePath
;
photo
[
@"width"
]
=
@
(
image
.
size
.
width
);
photo
[
@"height"
]
=
@
(
image
.
size
.
height
);
photo
[
@"size"
]
=
@
(
imageData
.
length
);
if
([
self
.
cameraOptions
sy_boolForKey
:
@"enableBase64"
])
{
photo
[
@"base64"
]
=
isPng
?[
NSString
stringWithFormat
:
@"data:image/png;base64,%@"
,
[
imageData
base64EncodedStringWithOptions
:
0
]]:[
NSString
stringWithFormat
:
@"data:image/jpeg;base64,%@"
,
[
imageData
base64EncodedStringWithOptions
:
0
]];
}
return
photo
;
}
-
(
NSDictionary
*
)
handleImageData
:
(
UIImage
*
)
image
quality
:
(
NSInteger
)
quality
{
-
(
NSDictionary
*
)
handleImageData
:
(
UIImage
*
)
image
quality
:
(
NSInteger
)
quality
{
NSMutableDictionary
*
photo
=
[
NSMutableDictionary
dictionary
];
NSMutableDictionary
*
photo
=
[
NSMutableDictionary
dictionary
];
NSData
*
imageData
=
UIImageJPEGRepresentation
(
image
,
quality
*
1
.
0
/
100
);
NSData
*
imageData
=
UIImageJPEGRepresentation
(
image
,
quality
*
1
.
0
/
100
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment