Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
VLC-Android
Manage
Activity
Members
Labels
Plan
Issues
531
Issue boards
Milestones
Wiki
Code
Merge requests
14
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VideoLAN
VLC-Android
Commits
72134aad
Commit
72134aad
authored
4 years ago
by
Nicolas Pomepuy
Browse files
Options
Downloads
Patches
Plain Diff
Avoid decoding too large bitmaps over http
Fixes
#1206
parent
23dbd9b0
No related branches found
Branches containing commit
Tags
3.1.6
Tags containing commit
1 merge request
!497
Avoid decoding too large bitmaps over http
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
application/tools/src/main/java/org/videolan/tools/HttpImageLoader.kt
+18
-3
18 additions, 3 deletions
...tools/src/main/java/org/videolan/tools/HttpImageLoader.kt
with
18 additions
and
3 deletions
application/tools/src/main/java/org/videolan/tools/HttpImageLoader.kt
+
18
−
3
View file @
72134aad
...
...
@@ -24,16 +24,17 @@
package
org.videolan.tools
import
android.graphics.Bitmap
import
android.graphics.BitmapFactory
import
android.util.Log
import
java.io.BufferedInputStream
import
java.io.IOException
import
java.io.InputStream
import
java.net.HttpURLConnection
import
java.net.URL
import
kotlin.math.floor
import
kotlin.math.max
object
HttpImageLoader
{
...
...
@@ -46,7 +47,21 @@ object HttpImageLoader {
val
url
=
URL
(
imageUrl
)
urlConnection
=
url
.
openConnection
()
as
HttpURLConnection
inputStream
=
BufferedInputStream
(
urlConnection
.
inputStream
)
icon
=
BitmapFactory
.
decodeStream
(
inputStream
)
val
options
=
BitmapFactory
.
Options
()
options
.
inJustDecodeBounds
=
true
BitmapFactory
.
decodeStream
(
inputStream
,
null
,
options
)
options
.
inJustDecodeBounds
=
false
//limit image to 150dp for the larger size
val
ratio
:
Float
=
max
(
options
.
outHeight
,
options
.
outWidth
).
toFloat
()
/
150
.
dp
.
toFloat
()
if
(
ratio
>
1
)
{
options
.
inSampleSize
=
floor
(
ratio
).
toInt
()
}
urlConnection
=
url
.
openConnection
()
as
HttpURLConnection
inputStream
=
BufferedInputStream
(
urlConnection
.
inputStream
)
icon
=
BitmapFactory
.
decodeStream
(
inputStream
,
null
,
options
)
BitmapCache
.
addBitmapToMemCache
(
imageUrl
,
icon
)
}
catch
(
ignored
:
IOException
)
{
Log
.
e
(
""
,
ignored
.
message
,
ignored
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment