Skip to content
43 changes: 38 additions & 5 deletions fixtures/html/images.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,39 @@
<head>
<meta charset="utf-8" />
<title>Images</title>
<style>
body {
background-color: #fff;
padding: 20px 10vw;
box-sizing: border-box;
}

h2 {
margin-bottom: 20px;
font-size: 3.5em;
}

section {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 20px;
}

#svg-image:hover {
background-color: #ca4747a8;
}
</style>
</head>

<body style="background-color: #fff;">
<h1>Images:</h1>
<img src="images/jsar-logo-00.png" style="transform:translateZ(10px);height:300px;" />
<img id="placeholder" />
<body>
<h2>Images:</h2>
<section>
<img src="images/jsar-logo-00.png" style="transform:translateZ(10px);height:300px;" />
<img id="svg-image" src="images/react-logo-00.svg" height="300" />
<img id="placeholder" />
</section>
</body>

<script>
Expand Down Expand Up @@ -48,7 +75,7 @@ <h1>Images:</h1>
console.info('new Image(100):', image2, image2.width, image2.height);
const image3 = new Image(100, 200);
console.info('new Image(100, 200):', image3, image3.width, image3.height);
image3.addEventListener('load', function() {
image3.addEventListener('load', function () {
console.info('[load] new Image(100, 200)', image3.width, image3.height);
});
image3.src = image.src;
Expand All @@ -60,6 +87,12 @@ <h1>Images:</h1>
placeholder.setAttribute('src', 'https://ar.rokidcdn.com/web-assets/yodaos-jsar/dist/images/a.jpg');
console.info('placeholder.src:', placeholder.src);
}, 1000);

setTimeout(() => {
// Update the SVG image size dynamically
const svgImage = document.getElementById('svg-image');
svgImage.style.height = '50vh';
}, 1000);
</script>

</html>
3 changes: 3 additions & 0 deletions fixtures/html/images/react-logo-00.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion src/client/builtin_scene/web_content_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,7 @@ namespace builtin_scene::web_renderer
SkBitmap bitmap;
// TODO(yorkie): support decoding this async?
if (canvas::ImageCodec::Decode(image.getUrlImageData(),
nullptr,
bitmap,
image.getUrl()))
{
Expand Down Expand Up @@ -1035,13 +1036,17 @@ namespace builtin_scene::web_renderer
SkRRect &roundedRect = content.rounded_rect_;
canvas->clipRRect(roundedRect, true);

SkPaint imagePaint;
imagePaint.setAntiAlias(true);
imagePaint.setStyle(SkPaint::kFill_Style);

SkRect srcRect = SkRect::MakeWH(skImage->width(), skImage->height());
SkRect dstRect = SkRect::MakeWH(content.logicalWidth(), content.logicalHeight());
canvas->drawImageRect(skImage,
srcRect,
dstRect,
SkSamplingOptions(),
nullptr,
&imagePaint,
SkCanvas::kStrict_SrcRectConstraint);
}
canvas->restore();
Expand Down
Loading