优化: 改进图片尺寸获取方式防止OOM

This commit is contained in:
SL 2025-05-29 10:58:07 +08:00
parent 16c6ca8d57
commit 9c7878d813
21 changed files with 76 additions and 53 deletions

View File

@ -1 +1 @@
2a8fa0fa06d069610eed09005b343994
5d168b3a13b32030e8635e7ebeeb842e

View File

@ -1 +1 @@
34a3a10b015c40e16a76fe75cb974d675a9cbda6
9adffa480b12d4cf387d65ab45c57f280d4279bb

View File

@ -1 +1 @@
eb0a4ee07731a3ef38f606b2978d16169a6f6388e3f33fa3a10c82f3b0c17bb0
fc1443c43330c3e40a8a2b0a6041419b3c5361a88eb4592d90fec48e622c147c

View File

@ -1 +1 @@
d1a0aa32976653fa04696f6d42edbe8152b59fdaf0135350cdefa14d571212571e85412c8f026a46e43069aadad3603358b63e262635a3716c948dab7b056750
c57204b220011558736e6372bb2542ab9582cd2c75da10df867746a475fd96b26198bb58b395a5d03d8d5f5174e43ab0b27536926279ea308aa2681ede1b2f7b

View File

@ -1 +1 @@
195544eb25003c80879e6390c389f4b5
1ee8fd344f3bee13dedc2412ea85c8a1

View File

@ -1 +1 @@
d7a3b759fd22ae6bb0cc7710e87c9f01b197afd8
dd1019d67fe7ab08a9533e3a2d4522c837e2ae60

View File

@ -1 +1 @@
2731b93ebd3aa8f457aa1dd2ac9634de1fb4641facabbc6683bc2b8575076c28
f1f8b7a5b49748f3f6b4765508bbae49351a04c756efb7cab1c36996fdc6fc32

View File

@ -1 +1 @@
67d5a21983e722346be407c14a7d0dab5de051789cf7764dfaacd686e770e75a9f8377b49af1e5570e29d6a7ae38fedaec5af4c6b17f631116d665570b92fc5d
e3b3bdf7e99fcffca5ff40b7d2c515e43af1975ec277883d7c3b80388253e632cf644dad984debdc92d3760e0b7c04a5ecce16c62ff9d066ef9b5c7e1f4737c9

View File

@ -25,11 +25,11 @@
{
"name": "WKIMLib_local-1.0.7.aar",
"url": "WKIMLib_local-1.0.7.aar",
"size": 619369,
"sha512": "67d5a21983e722346be407c14a7d0dab5de051789cf7764dfaacd686e770e75a9f8377b49af1e5570e29d6a7ae38fedaec5af4c6b17f631116d665570b92fc5d",
"sha256": "2731b93ebd3aa8f457aa1dd2ac9634de1fb4641facabbc6683bc2b8575076c28",
"sha1": "d7a3b759fd22ae6bb0cc7710e87c9f01b197afd8",
"md5": "195544eb25003c80879e6390c389f4b5"
"size": 619450,
"sha512": "e3b3bdf7e99fcffca5ff40b7d2c515e43af1975ec277883d7c3b80388253e632cf644dad984debdc92d3760e0b7c04a5ecce16c62ff9d066ef9b5c7e1f4737c9",
"sha256": "f1f8b7a5b49748f3f6b4765508bbae49351a04c756efb7cab1c36996fdc6fc32",
"sha1": "dd1019d67fe7ab08a9533e3a2d4522c837e2ae60",
"md5": "1ee8fd344f3bee13dedc2412ea85c8a1"
}
]
},
@ -106,11 +106,11 @@
{
"name": "WKIMLib_local-1.0.7.aar",
"url": "WKIMLib_local-1.0.7.aar",
"size": 619369,
"sha512": "67d5a21983e722346be407c14a7d0dab5de051789cf7764dfaacd686e770e75a9f8377b49af1e5570e29d6a7ae38fedaec5af4c6b17f631116d665570b92fc5d",
"sha256": "2731b93ebd3aa8f457aa1dd2ac9634de1fb4641facabbc6683bc2b8575076c28",
"sha1": "d7a3b759fd22ae6bb0cc7710e87c9f01b197afd8",
"md5": "195544eb25003c80879e6390c389f4b5"
"size": 619450,
"sha512": "e3b3bdf7e99fcffca5ff40b7d2c515e43af1975ec277883d7c3b80388253e632cf644dad984debdc92d3760e0b7c04a5ecce16c62ff9d066ef9b5c7e1f4737c9",
"sha256": "f1f8b7a5b49748f3f6b4765508bbae49351a04c756efb7cab1c36996fdc6fc32",
"sha1": "dd1019d67fe7ab08a9533e3a2d4522c837e2ae60",
"md5": "1ee8fd344f3bee13dedc2412ea85c8a1"
}
]
},
@ -128,11 +128,11 @@
{
"name": "WKIMLib_local-1.0.7-sources.jar",
"url": "WKIMLib_local-1.0.7-sources.jar",
"size": 328517,
"sha512": "d1a0aa32976653fa04696f6d42edbe8152b59fdaf0135350cdefa14d571212571e85412c8f026a46e43069aadad3603358b63e262635a3716c948dab7b056750",
"sha256": "eb0a4ee07731a3ef38f606b2978d16169a6f6388e3f33fa3a10c82f3b0c17bb0",
"sha1": "34a3a10b015c40e16a76fe75cb974d675a9cbda6",
"md5": "2a8fa0fa06d069610eed09005b343994"
"size": 328923,
"sha512": "c57204b220011558736e6372bb2542ab9582cd2c75da10df867746a475fd96b26198bb58b395a5d03d8d5f5174e43ab0b27536926279ea308aa2681ede1b2f7b",
"sha256": "fc1443c43330c3e40a8a2b0a6041419b3c5361a88eb4592d90fec48e622c147c",
"sha1": "9adffa480b12d4cf387d65ab45c57f280d4279bb",
"md5": "5d168b3a13b32030e8635e7ebeeb842e"
}
]
}

View File

@ -1 +1 @@
18f875f433f4b46c3a8f82d2102b4efd
4c79885e3a68e147b7c1224f413bcd43

View File

@ -1 +1 @@
5e3e6e61712a9bee911ec2191da0faef05f93430
3dffd7d2203e1d89e3a35a90543e3db528b2682b

View File

@ -1 +1 @@
b5c54156b3a952972c75cfed1f5dd52419426a975df9a863efa8eb36f1feae12
bcad34f63c34e515908d28d9310773b6604acf61d0bc51ae11bfc50347a2cbc4

View File

@ -1 +1 @@
0b3a1ba410c00e2566f0052b66121737164e4edc5defe64fd2aa7fd6e02ba05ccd9b2e0e13b603911d53a34ec9c10ee51fcd4c05719e19440c5da726484b45e3
f8eaf05854e3bb2b3ccc00966ab79425bd88c25e170ae94dc5a4817afc6a6e2b0a7c13a6daaa98c2c070371975216f6254e99fedd5ab6f36b2b58a41257ee156

View File

@ -8,6 +8,6 @@
<versions>
<version>1.0.7</version>
</versions>
<lastUpdated>20250524090841</lastUpdated>
<lastUpdated>20250529025503</lastUpdated>
</versioning>
</metadata>

View File

@ -1 +1 @@
2867162497a0539e3e3b0a1716f9feaa
26ae472fcffd2fe0b04d0a3133350e8d

View File

@ -1 +1 @@
e431ad1afdad3aff298476f1949e6dcb73bf52d2
7ad38bd49fd820be0253b040ef16b28958a46548

View File

@ -1 +1 @@
aa7f10d602787f0faf2fc1a55c04fd089c55313b1d22c30cf1aa24c24ab9a216
7ba7e14099eabac8987d6198c656c4226fb155c37fb3a808eaeeb6cc7581e630

View File

@ -1 +1 @@
3c7de45f238ee5d29b5c331b4c90ef396a87cc7a36550eeba7aa475e86f77da8d20e3373d177d46845e8e8d26c1ec106d2855ee1298c0763788a2583325b638f
0a2414a76b786281ac97d668dc59fb63f723659e0a1d3eb500f26c285ecbfc35b5d919c68169f6a70deb1b2f12f488ac3a5946149a7823cb1b40fae59e48a86b

View File

@ -1,6 +1,5 @@
package com.xinbida.wukongim.message;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Handler;
import android.os.Looper;
@ -52,14 +51,14 @@ import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.locks.ReentrantLock;
/**
@ -770,38 +769,62 @@ public class WKConnection {
}
boolean hasAttached = false;
//如果是图片消息
if (msg.baseContentMsgModel instanceof WKImageContent) {
WKImageContent imageContent = (WKImageContent) msg.baseContentMsgModel;
if (msg.baseContentMsgModel instanceof WKImageContent imageContent) {
if (!TextUtils.isEmpty(imageContent.localPath)) {
// try {
// File file = new File(imageContent.localPath);
// if (file.exists() && file.length() > 0) {
// hasAttached = true;
// Bitmap bitmap = BitmapFactory.decodeFile(imageContent.localPath);
// if (bitmap != null) {
// imageContent.width = bitmap.getWidth();
// imageContent.height = bitmap.getHeight();
// msg.baseContentMsgModel = imageContent;
// }
// }
// } catch (Exception ignored) {
// }
try {
File file = new File(imageContent.localPath);
if (file.exists() && file.length() > 0) {
hasAttached = true;
Bitmap bitmap = BitmapFactory.decodeFile(imageContent.localPath);
if (bitmap != null) {
imageContent.width = bitmap.getWidth();
imageContent.height = bitmap.getHeight();
msg.baseContentMsgModel = imageContent;
}
// 使用 Options 只解码尺寸信息
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true; // 只获取图片信息,不加载到内存
BitmapFactory.decodeFile(imageContent.localPath, options);
imageContent.width = options.outWidth;
imageContent.height = options.outHeight;
msg.baseContentMsgModel = imageContent;
}
} catch (Exception ignored) {
} catch (Exception e) {
WKLoggerUtils.getInstance().e("WKConnection", "Get image size failed: " + e.getMessage());
}
}
}
//视频消息
if (msg.baseContentMsgModel instanceof WKVideoContent) {
WKVideoContent videoContent = (WKVideoContent) msg.baseContentMsgModel;
if (msg.baseContentMsgModel instanceof WKVideoContent videoContent) {
if (!TextUtils.isEmpty(videoContent.localPath)) {
try {
File file = new File(videoContent.coverLocalPath);
if (file.exists() && file.length() > 0) {
hasAttached = true;
Bitmap bitmap = BitmapFactory.decodeFile(videoContent.coverLocalPath);
if (bitmap != null) {
videoContent.width = bitmap.getWidth();
videoContent.height = bitmap.getHeight();
msg.baseContentMsgModel = videoContent;
}
// Bitmap bitmap = BitmapFactory.decodeFile(videoContent.coverLocalPath);
// if (bitmap != null) {
// videoContent.width = bitmap.getWidth();
// videoContent.height = bitmap.getHeight();
// msg.baseContentMsgModel = videoContent;
// }
// 使用 Options 只解码尺寸信息
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true; // 只获取图片信息,不加载到内存
BitmapFactory.decodeFile(videoContent.coverLocalPath, options);
videoContent.width = options.outWidth;
videoContent.height = options.outHeight;
msg.baseContentMsgModel = videoContent;
}
} catch (Exception ignored) {