Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lib_base
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sikang
lib_base
Commits
13d4f873
Commit
13d4f873
authored
Oct 10, 2019
by
sikang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug fix
parent
b3bc1139
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
59 deletions
+10
-59
src/main/java/com/common/activity/TakePhotoActivity.java
+9
-52
src/main/java/com/common/widget/CameraView.java
+1
-7
No files found.
src/main/java/com/common/activity/TakePhotoActivity.java
View file @
13d4f873
...
...
@@ -8,32 +8,24 @@ import android.view.View;
import
android.widget.Button
;
import
android.widget.ImageView
;
import
com.common.base.BaseActivity
;
import
com.common.toolbox.tracker.TrackEvent
;
import
com.common.widget.CameraView
;
import
com.common.widget.TopBar
;
import
com.qmuiteam.qmui.util.QMUIStatusBarHelper
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
tech.starwin.R
;
import
com.common.base.BaseActivity
;
import
tech.starwin.impl.OnNoShakeClickListener
;
import
tech.starwin.utils.BitmapUtils
;
import
tech.starwin.utils.FileUtils
;
import
tech.starwin.utils.PreferencesManager
;
import
tech.starwin.utils.SPDataProvider
;
import
tech.starwin.utils.TrackEventHelper
;
import
tech.starwin.utils.context_utils.ActivityJumper
;
import
tech.starwin.utils.context_utils.EasyActivityResult
;
import
tech.starwin.utils.ui_utils.QMUIHelper
;
import
tech.starwin.utils.ui_utils.UIHelper
;
import
top.zibin.luban.Luban
;
import
top.zibin.luban.OnCompressListener
;
import
com.common.widget.CameraView
;
import
com.common.widget.TopBar
;
/**
* Created by SiKang on 2018/9/25.
...
...
@@ -112,7 +104,7 @@ public class TakePhotoActivity extends BaseActivity {
}
else
if
(
TextUtils
.
equals
(
type
,
PhotoType
.
WORK_CARD
.
name
()))
{
TrackEventHelper
.
logEvent
(
TrackEvent
.
Click
.
WORK_CARD_SHOT
);
photoType
=
PhotoType
.
WORK_CARD
;
}
else
{
}
else
{
photoType
=
PhotoType
.
OTHERS_IMG
;
}
...
...
@@ -121,62 +113,27 @@ public class TakePhotoActivity extends BaseActivity {
public
void
onEventClick
(
View
v
)
{
if
(
v
.
getId
()
==
R
.
id
.
button_shoot
)
{
cameraView
.
captureImage
(
bitmap
->
{
// long pix_size = bitmap.getWidth() * bitmap.getHeight();
// float scale = 720 * 1080 / (float) pix_size;
// BitmapUtils.scaleBitmap(bitmap, scale);
// if(TextUtils.equals(type, PhotoType.KTP.name())){
// SPDataProvider.saveKTPImage(bitmap);
// }else if(TextUtils.equals(type, PhotoType.WORK_CARD.name())){
// SPDataProvider.saveWorkImage(bitmap);
// }
// setResult(RESULT_OK);
// finish();
try
{
File
image
=
FileUtils
.
getImageFile
(
getApplicationContext
(),
photoType
.
img_path
);
if
(!
image
.
exists
())
{
image
.
mkdir
();
}
File
file
=
BitmapUtils
.
saveBitmapToSDCard
(
bitmap
,
image
,
100
);
if
(
file
==
null
)
{
setResult
(
RESULT_CANCELED
);
finish
();
return
;
}
//如果图片过大,则压缩
// long size = FileUtils.getFileSize(file) / 1024;
// if (FileUtils.getFileSize(file) / 1024 > 1024) {
// int quality = (int) (100 * (1024f / size));
// file = BitmapUtils.saveBitmapToSDCard(bitmap, image, quality);
//
// }
if
(
file
!=
null
)
{
//压缩
file
=
Luban
.
with
(
TakePhotoActivity
.
this
).
load
(
file
).
get
().
get
(
0
);
Intent
intent
=
new
Intent
();
Luban
.
with
(
TakePhotoActivity
.
this
)
.
load
(
file
)
.
ignoreBy
(
100
)
.
setFocusAlpha
(
false
)
.
setTargetDir
(
file
.
getParent
())
.
setCompressListener
(
new
OnCompressListener
()
{
@Override
public
void
onStart
()
{
}
@Override
public
void
onSuccess
(
File
file
)
{
intent
.
putExtra
(
"image_path"
,
file
.
getAbsolutePath
());
setResult
(
RESULT_OK
,
intent
);
finish
();
}
@Override
public
void
onError
(
Throwable
e
)
{
}
catch
(
Exception
e
)
{
setResult
(
RESULT_CANCELED
);
finish
();
}
}).
launch
();
});
}
else
if
(
v
.
getId
()
==
R
.
id
.
button_cancel
)
{
...
...
src/main/java/com/common/widget/CameraView.java
View file @
13d4f873
...
...
@@ -11,7 +11,6 @@ import android.util.AttributeSet;
import
android.view.SurfaceHolder
;
import
android.view.SurfaceView
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.util.List
;
...
...
@@ -106,19 +105,14 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback, C
public
void
onPreviewFrame
(
byte
[]
data
,
Camera
camera
)
{
if
(
previewPictureCallback
!=
null
&&
isCaptureImage
)
{
isCaptureImage
=
false
;
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
new
Thread
(()
->
{
Camera
.
Size
size
=
camera
.
getParameters
().
getPreviewSize
();
final
YuvImage
image
=
new
YuvImage
(
data
,
ImageFormat
.
NV21
,
size
.
width
,
size
.
height
,
null
);
ByteArrayOutputStream
stream
=
new
ByteArrayOutputStream
();
image
.
compressToJpeg
(
new
Rect
(
0
,
0
,
size
.
width
,
size
.
height
),
100
,
stream
);
Bitmap
bmp
=
BitmapFactory
.
decodeByteArray
(
stream
.
toByteArray
(),
0
,
stream
.
size
());
if
(
bmp
!=
null
)
{
previewPictureCallback
.
onImage
(
bmp
);
}
}
}).
start
();
}
}
...
...
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