Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
F
File Recovery RecycleBin
Project
Project
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wanglei
File Recovery RecycleBin
Commits
50198d08
Commit
50198d08
authored
Jul 29, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
af1f01c3
96cf42d9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
1 deletion
+32
-1
SimilarHelper.kt
...va/com/base/filerecoveryrecyclebin/utils/SimilarHelper.kt
+32
-1
No files found.
app/src/main/java/com/base/filerecoveryrecyclebin/utils/SimilarHelper.kt
View file @
50198d08
package
com.base.filerecoveryrecyclebin.utils
import
android.graphics.BitmapFactory
import
android.provider.MediaStore.Audio.Radio
import
java.io.File
import
kotlin.random.Random
...
...
@@ -46,9 +47,39 @@ object SimilarHelper {
}
private
fun
similarPercent
(
srcFile
:
File
,
compareFile
:
File
):
Int
{
return
Random
.
nextInt
(
60
,
100
)
var
similarityScore
:
Double
=
0.00
try
{
val
bitmap1
=
BitmapFactory
.
decodeFile
(
srcFile
.
absolutePath
)
val
bitmap2
=
BitmapFactory
.
decodeFile
(
compareFile
.
absolutePath
)
if
(
bitmap1
.
width
!=
bitmap2
.
width
||
bitmap1
.
height
!=
bitmap2
.
height
)
{
return
0
// 如果尺寸不同,则直接返回0
}
var
totalDifference
=
0L
for
(
x
in
0
until
bitmap1
.
width
)
{
for
(
y
in
0
until
bitmap1
.
height
)
{
val
pixel1
=
bitmap1
.
getPixel
(
x
,
y
)
val
pixel2
=
bitmap2
.
getPixel
(
x
,
y
)
val
redDifference
=
(
pixel1
shr
16
and
0
xff
)
-
(
pixel2
shr
16
and
0
xff
)
val
greenDifference
=
(
pixel1
shr
8
and
0
xff
)
-
(
pixel2
shr
8
and
0
xff
)
val
blueDifference
=
(
pixel1
and
0
xff
)
-
(
pixel2
and
0
xff
)
totalDifference
+=
(
redDifference
*
redDifference
+
greenDifference
*
greenDifference
+
blueDifference
*
blueDifference
)
}
}
// 计算相似度得分
val
maxDifference
=
bitmap1
.
width
*
bitmap1
.
height
*
3
*
255
*
255
similarityScore
=
(
1
-
totalDifference
.
toDouble
()
/
maxDifference
)
*
100
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
}
// 将相似度得分四舍五入到整数
return
similarityScore
.
toInt
().
coerceIn
(
0
,
100
)
}
}
\ No newline at end of file
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