Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
SteamTools
提交
adc56c8a
S
SteamTools
项目概览
jobily
/
SteamTools
10 个月 前同步成功
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SteamTools
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
adc56c8a
编写于
8月 22, 2023
作者:
A
Aigio
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Windows ICO 格式编码器
上级
a96f8e83
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
169 addition
and
0 deletion
+169
-0
src/BD.WTTS.Client/Helpers/IcoEncoder.cs
src/BD.WTTS.Client/Helpers/IcoEncoder.cs
+113
-0
src/BD.WTTS.UnitTest/IcoTest.cs
src/BD.WTTS.UnitTest/IcoTest.cs
+56
-0
未找到文件。
src/BD.WTTS.Client/Helpers/IcoEncoder.cs
0 → 100644
浏览文件 @
adc56c8a
using
SkiaSharp
;
// ReSharper disable once CheckNamespace
namespace
BD.WTTS
;
/// <summary>
/// Windows ICO 格式编码器
/// </summary>
public
static
class
IcoEncoder
{
public
static
void
Encode
(
Stream
stream
,
IReadOnlyList
<
SKBitmap
>
bitmaps
)
{
// 写入文件头
stream
.
WriteByte
(
0
);
stream
.
WriteByte
(
0
);
stream
.
WriteByte
(
1
);
// 1 为图标,2 为光标
stream
.
WriteByte
(
0
);
// 写入长度,2 位
stream
.
Write
(
BitConverter
.
GetBytes
(
Convert
.
ToInt16
(
bitmaps
.
Count
)));
Class253
class253_1
;
List
<
Class253
>
class253List
=
new
();
List
<
MemoryStream
>
memoryStreamList
=
new
();
for
(
int
index
=
0
;
index
<
bitmaps
.
Count
;
++
index
)
{
var
image
=
bitmaps
[
index
];
MemoryStream
memoryStream1
=
new
();
image
.
Encode
(
memoryStream1
,
SKEncodedImageFormat
.
Png
,
100
);
int
num1
=
(
int
)
memoryStream1
.
Length
;
memoryStreamList
.
Add
(
memoryStream1
);
class253_1
=
new
(
image
.
Width
,
image
.
Height
,
0
,
image
.
BytesPerPixel
);
class253_1
.
method_14
(
num1
);
Class253
class253_2
=
class253_1
;
class253List
.
Add
(
class253_2
);
}
Dictionary
<
Class253
,
MemoryStream
>
dictionary_0
=
new
();
for
(
int
index
=
0
;
index
<
memoryStreamList
.
Count
;
++
index
)
dictionary_0
.
Add
(
class253List
[
index
],
memoryStreamList
[
index
]);
smethod_6
(
dictionary_0
);
smethod_21
(
stream
,
dictionary_0
);
}
// it's just works
#pragma warning disable IDE1006 // 命名样式
static
void
smethod_6
(
Dictionary
<
Class253
,
MemoryStream
>
dictionary_0
)
{
var
class253List
=
dictionary_0
.
Keys
.
ToArray
();
Class253
class253_1
=
class253List
[
0
];
class253_1
.
method_16
(
6
+
(
16
*
dictionary_0
.
Count
));
int
int_0
=
class253_1
.
method_15
()
+
class253_1
.
method_13
();
for
(
int
index
=
1
;
index
<
class253List
.
Length
;
++
index
)
{
Class253
class253_2
=
class253List
[
index
];
class253_2
.
method_16
(
int_0
);
int_0
+=
class253_2
.
method_13
();
}
}
sealed
class
Class253
{
byte
[]
byte_0
=
null
!;
public
Class253
(
int
int_0
,
int
int_1
,
int
int_2
,
int
int_3
,
int
int_4
,
int
int_5
)
{
List
<
byte
>
byteList
=
new
List
<
byte
>()
{
(
byte
)
int_0
,
(
byte
)
int_1
,
int_3
<=
8
?
(
byte
)
int_2
:
(
byte
)
0
,
0
,
};
byteList
.
AddRange
(
BitConverter
.
GetBytes
((
short
)
0
));
byteList
.
AddRange
(
BitConverter
.
GetBytes
((
short
)
int_3
));
byteList
.
AddRange
(
BitConverter
.
GetBytes
(
int_4
));
byteList
.
AddRange
(
BitConverter
.
GetBytes
(
int_5
));
method_1
(
byteList
.
ToArray
());
}
public
Class253
(
int
int_0
,
int
int_1
,
int
int_2
,
int
int_3
)
:
this
(
int_0
,
int_1
,
int_2
,
int_3
,
0
,
0
)
{
}
public
byte
[]
method_0
()
=>
byte_0
;
private
void
method_1
(
byte
[]
byte_1
)
=>
byte_0
=
byte_1
;
public
int
method_13
()
=>
BitConverter
.
ToInt32
(
method_0
(),
8
);
public
void
method_14
(
int
int_0
)
=>
BitConverter
.
GetBytes
(
int_0
).
CopyTo
(
method_0
(),
8
);
public
int
method_15
()
=>
BitConverter
.
ToInt32
(
method_0
(),
12
);
public
void
method_16
(
int
int_0
)
=>
BitConverter
.
GetBytes
(
int_0
).
CopyTo
(
method_0
(),
12
);
}
static
void
smethod_21
(
Stream
stream_0
,
Dictionary
<
Class253
,
MemoryStream
>
dictionary_0
)
{
smethod_6
(
dictionary_0
);
foreach
(
Class253
key
in
dictionary_0
.
Keys
)
stream_0
.
Write
(
key
.
method_0
(),
0
,
16
);
foreach
(
MemoryStream
memoryStream
in
dictionary_0
.
Values
)
{
using
(
memoryStream
)
memoryStream
.
WriteTo
(
stream_0
);
}
}
}
src/BD.WTTS.UnitTest/IcoTest.cs
0 → 100644
浏览文件 @
adc56c8a
using
SkiaSharp
;
namespace
BD.WTTS.UnitTest
;
/// <summary>
/// Windows ICO 格式测试
/// </summary>
public
sealed
class
IcoTest
{
/// <summary>
/// Windows ICO 格式编码测试
/// </summary>
[
Test
]
public
void
EncodeTest
()
{
var
logo512Path
=
Path
.
Combine
(
ProjectUtils
.
ProjPath
,
"res"
,
"icons"
,
"app"
,
"v3"
,
"Logo_512.png"
);
SKBitmap
[]?
logoBitmaps
=
null
;
try
{
using
var
logo512Bitmap
=
SKBitmap
.
Decode
(
logo512Path
);
logoBitmaps
=
new
[]
{
logo512Bitmap
}.
Concat
(
new
[]
{
256
,
128
,
96
,
64
,
48
,
32
,
24
,
16
}
.
Select
(
x
=>
logo512Bitmap
.
Resize
(
new
SKSizeI
{
Height
=
x
,
Width
=
x
},
SKFilterQuality
.
High
)))
.
ToArray
();
// 根据 512 大小生成所有挡位的位图数组
var
savePath
=
$"
{
logo512Path
}
.ico"
;
try
{
// 创建 ico 文件内存流
using
var
fs
=
new
FileStream
(
savePath
,
FileMode
.
Create
,
FileAccess
.
ReadWrite
,
FileShare
.
ReadWrite
|
FileShare
.
Delete
);
IcoEncoder
.
Encode
(
fs
,
logoBitmaps
);
TestContext
.
WriteLine
(
savePath
);
}
finally
{
// 删除生成的文件,清理
IOPath
.
FileTryDelete
(
savePath
);
}
}
finally
{
if
(
logoBitmaps
!=
null
)
{
foreach
(
var
logoBitmap
in
logoBitmaps
)
{
logoBitmap
.
Dispose
();
}
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录