Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sxychenjing
engine
提交
a17036ca
E
engine
项目概览
sxychenjing
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
a17036ca
编写于
9月 29, 2020
作者:
Y
Yegor
提交者:
GitHub
9月 29, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix EnginePicture.toImage; implement rawRgba toByteData; add test (#21370)
上级
4f8a6f04
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
76 addition
and
9 deletion
+76
-9
lib/web_ui/lib/src/engine/bitmap_canvas.dart
lib/web_ui/lib/src/engine/bitmap_canvas.dart
+2
-2
lib/web_ui/lib/src/engine/canvas_pool.dart
lib/web_ui/lib/src/engine/canvas_pool.dart
+2
-2
lib/web_ui/lib/src/engine/html_image_codec.dart
lib/web_ui/lib/src/engine/html_image_codec.dart
+9
-0
lib/web_ui/lib/src/engine/picture.dart
lib/web_ui/lib/src/engine/picture.dart
+13
-5
lib/web_ui/test/engine/image_to_byte_data_test.dart
lib/web_ui/test/engine/image_to_byte_data_test.dart
+50
-0
未找到文件。
lib/web_ui/lib/src/engine/bitmap_canvas.dart
浏览文件 @
a17036ca
...
...
@@ -201,8 +201,8 @@ class BitmapCanvas extends EngineCanvas {
return
_devicePixelRatio
==
EngineWindow
.
browserDevicePixelRatio
;
}
/// Returns a
data
URI containing a representation of the image in this
/// canvas.
/// Returns a
"data://"
URI containing a representation of the image in this
/// canvas
in PNG format
.
String
toDataUrl
()
{
return
_canvasPool
.
toDataUrl
();
}
...
...
lib/web_ui/lib/src/engine/canvas_pool.dart
浏览文件 @
a17036ca
...
...
@@ -319,8 +319,8 @@ class _CanvasPool extends _SaveStackTracking {
}
}
// Returns a
data
URI containing a representation of the image in this
// canvas.
// Returns a
"data://"
URI containing a representation of the image in this
// canvas
in PNG format
.
String
toDataUrl
()
=>
_canvas
!.
toDataUrl
();
@override
...
...
lib/web_ui/lib/src/engine/html_image_codec.dart
浏览文件 @
a17036ca
...
...
@@ -139,6 +139,15 @@ class HtmlImage implements ui.Image {
@override
Future
<
ByteData
?>
toByteData
({
ui
.
ImageByteFormat
format
=
ui
.
ImageByteFormat
.
rawRgba
})
{
if
(
format
==
ui
.
ImageByteFormat
.
rawRgba
)
{
final
html
.
CanvasElement
canvas
=
html
.
CanvasElement
()
..
width
=
width
..
height
=
height
;
final
html
.
CanvasRenderingContext2D
ctx
=
canvas
.
context2D
;
ctx
.
drawImage
(
imgElement
,
0
,
0
);
final
html
.
ImageData
imageData
=
ctx
.
getImageData
(
0
,
0
,
width
,
height
);
return
Future
.
value
(
imageData
.
data
.
buffer
.
asByteData
());
}
if
(
imgElement
.
src
?.
startsWith
(
'data:'
)
==
true
)
{
final
data
=
UriData
.
fromUri
(
Uri
.
parse
(
imgElement
.
src
!));
return
Future
.
value
(
data
.
contentAsBytes
().
buffer
.
asByteData
());
...
...
lib/web_ui/lib/src/engine/picture.dart
浏览文件 @
a17036ca
...
...
@@ -54,11 +54,19 @@ class EnginePicture implements ui.Picture {
..
src
=
imageDataUrl
..
width
=
width
..
height
=
height
;
return
HtmlImage
(
imageElement
,
width
,
height
,
);
// The image loads asynchronously. We need to wait before returning,
// otherwise the returned HtmlImage will be temporarily unusable.
final
Completer
<
ui
.
Image
>
onImageLoaded
=
Completer
<
ui
.
Image
>.
sync
();
imageElement
.
onError
.
first
.
then
(
onImageLoaded
.
completeError
);
imageElement
.
onLoad
.
first
.
then
((
_
)
{
onImageLoaded
.
complete
(
HtmlImage
(
imageElement
,
width
,
height
,
));
});
return
onImageLoaded
.
future
;
}
@override
...
...
lib/web_ui/test/
golden_tests/engine/canvas_to_picture
_test.dart
→
lib/web_ui/test/
engine/image_to_byte_data
_test.dart
浏览文件 @
a17036ca
...
...
@@ -3,7 +3,7 @@
// found in the LICENSE file.
// @dart = 2.6
import
'dart:
html'
as
html
;
import
'dart:
typed_data'
;
import
'package:ui/ui.dart'
;
import
'package:ui/src/engine.dart'
;
...
...
@@ -16,40 +16,35 @@ void main() {
}
void
testMain
(
)
async
{
final
Rect
region
=
Rect
.
fromLTWH
(
0
,
0
,
500
,
500
);
setUp
(()
async
{
debugShowClipLayers
=
true
;
SurfaceSceneBuilder
.
debugForgetFrameScene
();
for
(
html
.
Node
scene
in
html
.
document
.
querySelectorAll
(
'flt-scene'
))
{
scene
.
remove
();
}
await
webOnlyInitializePlatform
();
webOnlyFontCollection
.
debugRegisterTestFonts
();
await
webOnlyFontCollection
.
ensureFontsLoaded
();
});
test
(
'Convert Canvas to Picture'
,
()
async
{
final
SurfaceSceneBuilder
builder
=
SurfaceSceneBuilder
();
final
Picture
testPicture
=
await
_drawTestPictureWithCircle
(
region
);
builder
.
addPicture
(
Offset
.
zero
,
testPicture
);
html
.
document
.
body
.
append
(
builder
.
build
()
.
webOnlyRootElement
);
//await matchGoldenFile('canvas_to_picture.png', region: region, write: true);
test
(
'Picture.toImage().toByteData()'
,
()
async
{
final
EnginePictureRecorder
recorder
=
PictureRecorder
();
final
RecordingCanvas
canvas
=
recorder
.
beginRecording
(
Rect
.
fromLTRB
(
0
,
0
,
2
,
2
));
canvas
.
drawColor
(
Color
(
0xFFCCDD00
),
BlendMode
.
srcOver
);
final
Picture
testPicture
=
recorder
.
endRecording
();
final
Image
testImage
=
await
testPicture
.
toImage
(
2
,
2
);
final
ByteData
bytes
=
await
testImage
.
toByteData
(
format:
ImageByteFormat
.
rawRgba
);
expect
(
bytes
.
buffer
.
asUint32List
(),
<
int
>[
0xFF00DDCC
,
0xFF00DDCC
,
0xFF00DDCC
,
0xFF00DDCC
],
);
final
ByteData
pngBytes
=
await
testImage
.
toByteData
(
format:
ImageByteFormat
.
png
);
// PNG-encoding is browser-specific, but the header is standard. We only
// test the header.
final
List
<
int
>
pngHeader
=
<
int
>[
137
,
80
,
78
,
71
,
13
,
10
,
26
,
10
];
expect
(
pngBytes
.
buffer
.
asUint8List
().
sublist
(
0
,
pngHeader
.
length
),
pngHeader
,
);
});
}
Picture
_drawTestPictureWithCircle
(
Rect
region
)
{
final
EnginePictureRecorder
recorder
=
PictureRecorder
();
final
RecordingCanvas
canvas
=
recorder
.
beginRecording
(
region
);
canvas
.
drawOval
(
region
,
Paint
()
..
style
=
PaintingStyle
.
fill
..
color
=
Color
(
0xFF00FF00
));
return
recorder
.
endRecording
();
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录