Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
S
screenshot
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
openSourceLibrary
screenshot
Commits
4dd23015
Unverified
提交
4dd23015
authored
7月 09, 2021
作者:
Sachin
提交者:
GitHub
7月 09, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #57 from SachinGanesh/issues_49
fix: issue #49
上级
b49a6b97
0dd43440
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
16 行增加
和
6 行删除
+16
-6
screenshot.dart
lib/screenshot.dart
+16
-6
没有找到文件。
lib/screenshot.dart
浏览文件 @
4dd23015
...
...
@@ -44,12 +44,12 @@ class ScreenshotController {
//Delay is required. See Issue https://github.com/flutter/flutter/issues/22308
return
new
Future
.
delayed
(
delay
,
()
async
{
try
{
ui
.
Image
image
=
await
captureAsUiImage
(
ui
.
Image
?
image
=
await
captureAsUiImage
(
delay:
Duration
.
zero
,
pixelRatio:
pixelRatio
,
);
ByteData
?
byteData
=
await
image
.
toByteData
(
format:
ui
.
ImageByteFormat
.
png
);
await
image
?
.
toByteData
(
format:
ui
.
ImageByteFormat
.
png
);
Uint8List
?
pngBytes
=
byteData
?.
buffer
.
asUint8List
();
return
pngBytes
;
...
...
@@ -59,16 +59,20 @@ class ScreenshotController {
});
}
Future
<
ui
.
Image
>
captureAsUiImage
(
Future
<
ui
.
Image
?
>
captureAsUiImage
(
{
double
?
pixelRatio:
1
,
Duration
delay:
const
Duration
(
milliseconds:
20
)})
{
//Delay is required. See Issue https://github.com/flutter/flutter/issues/22308
return
new
Future
.
delayed
(
delay
,
()
async
{
try
{
RenderRepaintBoundary
boundary
=
this
var
findRenderObject
=
this
.
_containerKey
.
currentContext
?.
findRenderObject
()
as
RenderRepaintBoundary
;
?.
findRenderObject
();
if
(
findRenderObject
==
null
){
return
null
;
}
RenderRepaintBoundary
boundary
=
findRenderObject
as
RenderRepaintBoundary
;
BuildContext
?
context
=
_containerKey
.
currentContext
;
if
(
pixelRatio
==
null
)
{
if
(
context
!=
null
)
...
...
@@ -89,7 +93,7 @@ class ScreenshotController {
Size
logicalSize
=
ui
.
window
.
physicalSize
/
ui
.
window
.
devicePixelRatio
;
Size
imageSize
=
ui
.
window
.
physicalSize
;
assert
(
logicalSize
.
aspectRatio
==
imageSize
.
aspectRatio
);
assert
(
logicalSize
.
aspectRatio
.
toPrecision
(
5
)
==
imageSize
.
aspectRatio
.
toPrecision
(
5
)
);
final
RenderView
renderView
=
RenderView
(
window:
ui
.
window
,
...
...
@@ -168,3 +172,8 @@ class ScreenshotState extends State<Screenshot> with TickerProviderStateMixin {
);
}
}
extension
Ex
on
double
{
double
toPrecision
(
int
n
)
=>
double
.
parse
(
toStringAsFixed
(
n
));
}
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论