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
68c3893b
Unverified
Commit
68c3893b
authored
Jan 03, 2019
by
少言
Committed by
GitHub
Jan 03, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #91 from NikiLee2016/branch-base64
Branch base64
parents
49a9ddd0
031d0910
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
69 deletions
+72
-69
AndroidManifest.xml
android/src/main/AndroidManifest.xml
+0
-4
RNSyanImagePickerModule.java
...c/main/java/com/reactlibrary/RNSyanImagePickerModule.java
+72
-65
No files found.
android/src/main/AndroidManifest.xml
View file @
68c3893b
<manifest
xmlns:android=
"http://schemas.android.com/apk/res/android"
package=
"com.reactlibrary"
>
<uses-permission
android:name=
"android.permission.READ_EXTERNAL_STORAGE"
/>
<uses-permission
android:name=
"android.permission.WRITE_EXTERNAL_STORAGE"
/>
<uses-permission
android:name=
"android.permission.CAMERA"
/>
<application>
</application>
...
...
android/src/main/java/com/reactlibrary/RNSyanImagePickerModule.java
View file @
68c3893b
...
...
@@ -205,76 +205,83 @@ public class RNSyanImagePickerModule extends ReactContextBaseJavaModule {
private
final
ActivityEventListener
mActivityEventListener
=
new
BaseActivityEventListener
()
{
@Override
public
void
onActivityResult
(
Activity
activity
,
int
requestCode
,
int
resultCode
,
Intent
data
)
{
switch
(
requestCode
)
{
case
PictureConfig
.
CHOOSE_REQUEST
:
List
<
LocalMedia
>
tmpSelectList
=
PictureSelector
.
obtainMultipleResult
(
data
);
boolean
isRecordSelected
=
cameraOptions
.
getBoolean
(
"isRecordSelected"
);
if
(!
tmpSelectList
.
isEmpty
()
&&
isRecordSelected
)
{
selectList
=
tmpSelectList
;
}
WritableArray
imageList
=
new
WritableNativeArray
();
boolean
enableBase64
=
cameraOptions
.
getBoolean
(
"enableBase64"
);
for
(
LocalMedia
media
:
tmpSelectList
)
{
WritableMap
aImage
=
new
WritableNativeMap
();
BitmapFactory
.
Options
options
=
new
BitmapFactory
.
Options
();
options
.
inJustDecodeBounds
=
true
;
if
(!
media
.
isCompressed
())
{
BitmapFactory
.
decodeFile
(
media
.
getPath
(),
options
);
aImage
.
putDouble
(
"width"
,
options
.
outWidth
);
aImage
.
putDouble
(
"height"
,
options
.
outHeight
);
aImage
.
putString
(
"type"
,
"image"
);
aImage
.
putString
(
"uri"
,
"file://"
+
media
.
getPath
());
//decode to bitmap
Bitmap
bitmap
=
BitmapFactory
.
decodeFile
(
media
.
getPath
());
aImage
.
putInt
(
"size"
,
bitmap
.
getByteCount
());
//base64 encode
if
(
enableBase64
)
{
String
encodeString
=
getBase64EncodeString
(
bitmap
);
aImage
.
putString
(
"base64"
,
encodeString
);
}
}
else
{
// 压缩过,取 media.getCompressPath();
BitmapFactory
.
decodeFile
(
media
.
getCompressPath
(),
options
);
aImage
.
putDouble
(
"width"
,
options
.
outWidth
);
aImage
.
putDouble
(
"height"
,
options
.
outHeight
);
aImage
.
putString
(
"type"
,
"image"
);
aImage
.
putString
(
"uri"
,
"file://"
+
media
.
getCompressPath
());
//decode to bitmap
Bitmap
bitmap
=
BitmapFactory
.
decodeFile
(
media
.
getCompressPath
());
aImage
.
putInt
(
"size"
,
bitmap
.
getByteCount
());
//base64 encode
if
(
enableBase64
)
{
String
encodeString
=
getBase64EncodeString
(
bitmap
);
aImage
.
putString
(
"base64"
,
encodeString
);
}
}
if
(
media
.
isCut
())
{
aImage
.
putString
(
"original_uri"
,
"file://"
+
media
.
getCutPath
());
}
else
{
aImage
.
putString
(
"original_uri"
,
"file://"
+
media
.
getPath
());
}
imageList
.
pushMap
(
aImage
);
}
if
(
tmpSelectList
.
isEmpty
())
{
invokeError
();
}
else
{
invokeSuccessWithResult
(
imageList
);
public
void
onActivityResult
(
Activity
activity
,
int
requestCode
,
int
resultCode
,
final
Intent
data
)
{
if
(
requestCode
==
PictureConfig
.
CHOOSE_REQUEST
){
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
onGetResult
(
data
);
}
}).
run
();
}
}
};
private
void
onGetResult
(
Intent
data
){
List
<
LocalMedia
>
tmpSelectList
=
PictureSelector
.
obtainMultipleResult
(
data
);
boolean
isRecordSelected
=
cameraOptions
.
getBoolean
(
"isRecordSelected"
);
if
(!
tmpSelectList
.
isEmpty
()
&&
isRecordSelected
)
{
selectList
=
tmpSelectList
;
}
WritableArray
imageList
=
new
WritableNativeArray
();
boolean
enableBase64
=
cameraOptions
.
getBoolean
(
"enableBase64"
);
for
(
LocalMedia
media
:
tmpSelectList
)
{
WritableMap
aImage
=
new
WritableNativeMap
();
BitmapFactory
.
Options
options
=
new
BitmapFactory
.
Options
();
options
.
inJustDecodeBounds
=
true
;
if
(!
media
.
isCompressed
())
{
BitmapFactory
.
decodeFile
(
media
.
getPath
(),
options
);
aImage
.
putDouble
(
"width"
,
options
.
outWidth
);
aImage
.
putDouble
(
"height"
,
options
.
outHeight
);
aImage
.
putString
(
"type"
,
"image"
);
aImage
.
putString
(
"uri"
,
"file://"
+
media
.
getPath
());
//decode to bitmap
Bitmap
bitmap
=
BitmapFactory
.
decodeFile
(
media
.
getPath
());
aImage
.
putInt
(
"size"
,
bitmap
.
getByteCount
());
//base64 encode
if
(
enableBase64
)
{
String
encodeString
=
getBase64EncodeString
(
bitmap
);
aImage
.
putString
(
"base64"
,
encodeString
);
}
}
else
{
// 压缩过,取 media.getCompressPath();
BitmapFactory
.
decodeFile
(
media
.
getCompressPath
(),
options
);
aImage
.
putDouble
(
"width"
,
options
.
outWidth
);
aImage
.
putDouble
(
"height"
,
options
.
outHeight
);
aImage
.
putString
(
"type"
,
"image"
);
aImage
.
putString
(
"uri"
,
"file://"
+
media
.
getCompressPath
());
//decode to bitmap
Bitmap
bitmap
=
BitmapFactory
.
decodeFile
(
media
.
getCompressPath
());
aImage
.
putInt
(
"size"
,
bitmap
.
getByteCount
());
//base64 encode
if
(
enableBase64
)
{
String
encodeString
=
getBase64EncodeString
(
bitmap
);
aImage
.
putString
(
"base64"
,
encodeString
);
}
}
if
(
media
.
isCut
())
{
aImage
.
putString
(
"original_uri"
,
"file://"
+
media
.
getCutPath
());
}
else
{
aImage
.
putString
(
"original_uri"
,
"file://"
+
media
.
getPath
());
}
imageList
.
pushMap
(
aImage
);
}
if
(
tmpSelectList
.
isEmpty
())
{
invokeError
();
}
else
{
invokeSuccessWithResult
(
imageList
);
}
}
/**
* 获取图片base64编码字符串
* @param bitmap Bitmap对象
...
...
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