Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
PrictureTranslate
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
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
bixing
PrictureTranslate
Commits
d3446114
Commit
d3446114
authored
Sep 27, 2023
by
bixing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
a358c220
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
9 deletions
+30
-9
PictureTranslateShowPhotoActivity.java
...translate/activity/PictureTranslateShowPhotoActivity.java
+30
-9
No files found.
app/src/main/java/com/ads/cal/picturetranslate/activity/PictureTranslateShowPhotoActivity.java
View file @
d3446114
...
@@ -11,6 +11,7 @@ import android.os.Bundle;
...
@@ -11,6 +11,7 @@ import android.os.Bundle;
import
android.text.TextUtils
;
import
android.text.TextUtils
;
import
android.view.View
;
import
android.view.View
;
import
android.view.WindowManager
;
import
android.view.WindowManager
;
import
android.widget.EditText
;
import
android.widget.ImageView
;
import
android.widget.ImageView
;
import
android.widget.LinearLayout
;
import
android.widget.LinearLayout
;
import
android.widget.Toast
;
import
android.widget.Toast
;
...
@@ -132,6 +133,7 @@ import java.io.OutputStream;
...
@@ -132,6 +133,7 @@ import java.io.OutputStream;
private
Uri
uri
=
null
;
private
Uri
uri
=
null
;
private
String
path
;
private
String
path
;
private
Bitmap
bitmap
;
private
void
initData
()
{
private
void
initData
()
{
Intent
intent
=
getIntent
();
Intent
intent
=
getIntent
();
...
@@ -145,7 +147,7 @@ import java.io.OutputStream;
...
@@ -145,7 +147,7 @@ import java.io.OutputStream;
if
(
path
==
null
||
path
.
isEmpty
())
{
if
(
path
==
null
||
path
.
isEmpty
())
{
Toast
.
makeText
(
this
,
getString
(
R
.
string
.
app_toast_the_file_is_corrupted
),
Toast
.
LENGTH_SHORT
).
show
();
Toast
.
makeText
(
this
,
getString
(
R
.
string
.
app_toast_the_file_is_corrupted
),
Toast
.
LENGTH_SHORT
).
show
();
}
else
{
}
else
{
Bitmap
bitmap
=
BitmapFactory
.
decodeFile
(
path
);
bitmap
=
BitmapFactory
.
decodeFile
(
path
);
ExifInterface
exif
=
null
;
ExifInterface
exif
=
null
;
try
{
try
{
exif
=
new
ExifInterface
(
path
);
exif
=
new
ExifInterface
(
path
);
...
@@ -157,7 +159,7 @@ import java.io.OutputStream;
...
@@ -157,7 +159,7 @@ import java.io.OutputStream;
}
}
public
void
setImageBitmap
(
Bitmap
bitmap
,
ExifInterface
exif
)
{
public
void
setImageBitmap
(
Bitmap
bitmap
,
ExifInterface
exif
)
{
if
(
bitmap
==
null
)
{
if
(
bitmap
==
null
||
bitmap
.
isRecycled
()
)
{
return
;
return
;
}
}
...
@@ -165,16 +167,24 @@ import java.io.OutputStream;
...
@@ -165,16 +167,24 @@ import java.io.OutputStream;
int
orientation
=
exif
!=
null
?
exif
.
getAttributeInt
(
ExifInterface
.
TAG_ORIENTATION
,
ExifInterface
.
ORIENTATION_NORMAL
)
:
ExifInterface
.
ORIENTATION_NORMAL
;
int
orientation
=
exif
!=
null
?
exif
.
getAttributeInt
(
ExifInterface
.
TAG_ORIENTATION
,
ExifInterface
.
ORIENTATION_NORMAL
)
:
ExifInterface
.
ORIENTATION_NORMAL
;
int
rotate
=
getRotateValueForOrientation
(
orientation
);
int
rotate
=
getRotateValueForOrientation
(
orientation
);
LogUtils
.
e
(
rotate
+
""
);
if
(
rotate
!=
0
)
{
if
(
rotate
!=
0
)
{
matrix
.
postRotate
(
rotate
);
matrix
.
postRotate
(
rotate
);
Bitmap
rotatedBitmap
=
Bitmap
.
createBitmap
(
bitmap
,
0
,
0
,
bitmap
.
getWidth
(),
bitmap
.
getHeight
(),
matrix
,
true
);
if
(
rotatedBitmap
!=
null
)
{
imageView
.
setImageBitmap
(
rotatedBitmap
);
}
if
(
bitmap
.
isRecycled
())
{
return
;
}
try
{
bitmap
.
recycle
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
else
{
imageView
.
setImageBitmap
(
bitmap
);
}
}
Bitmap
rotatedBitmap
=
Bitmap
.
createBitmap
(
bitmap
,
0
,
0
,
bitmap
.
getWidth
(),
bitmap
.
getHeight
(),
matrix
,
true
);
imageView
.
setImageBitmap
(
rotatedBitmap
);
if
(
bitmap
.
isRecycled
())
{
return
;
}
bitmap
.
recycle
();
}
}
private
Bitmap
rotateBitmapIfNecessary
(
Bitmap
bitmap
,
ExifInterface
exif
)
{
private
Bitmap
rotateBitmapIfNecessary
(
Bitmap
bitmap
,
ExifInterface
exif
)
{
...
@@ -240,6 +250,17 @@ import java.io.OutputStream;
...
@@ -240,6 +250,17 @@ import java.io.OutputStream;
return
resultPath
;
return
resultPath
;
}
}
@Override
protected
void
onDestroy
()
{
super
.
onDestroy
();
imageView
.
setImageDrawable
(
null
);
imageView
.
setImageBitmap
(
null
);
if
(
bitmap
==
null
||
bitmap
.
isRecycled
())
{
return
;
}
bitmap
.
recycle
();
}
public
static
void
startPictureTranslateShowPhotoActivity
(
Context
context
,
Uri
uri
)
{
public
static
void
startPictureTranslateShowPhotoActivity
(
Context
context
,
Uri
uri
)
{
Intent
intent
=
new
Intent
(
context
,
PictureTranslateShowPhotoActivity
.
class
);
Intent
intent
=
new
Intent
(
context
,
PictureTranslateShowPhotoActivity
.
class
);
intent
.
putExtra
(
"uri"
,
uri
);
intent
.
putExtra
(
"uri"
,
uri
);
...
...
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