Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/image optimize #879

Merged
merged 31 commits into from Dec 6, 2021
Merged

Feat/image optimize #879

merged 31 commits into from Dec 6, 2021

Conversation

andycall
Copy link
Member

@andycall andycall commented Nov 16, 2021

Fixed #865

  1. 支持通过用户设定的图片尺寸,在加载阶段自动裁剪出合适尺寸的图片。
  2. 优化图片加载逻辑,当图片被卸载,但是没有销毁的情况下,保留 imageStream。只有 dispose 才会完整销毁图片所持有的资源。
  3. 支持复用 imageCache,相同的图片不会被重复加载两次

Base automatically changed from feat-css-style-sheet to main November 19, 2021 14:03
@andycall andycall changed the title [WIP]: Feat/image optimize Feat/image optimize Nov 26, 2021
kraken/lib/src/dom/elements/img.dart Outdated Show resolved Hide resolved
kraken/lib/src/dom/elements/img.dart Show resolved Hide resolved
kraken/lib/src/css/values/url.dart Outdated Show resolved Hide resolved
kraken/lib/src/dom/elements/img.dart Show resolved Hide resolved
@tylorvan
Copy link

image

lazy 加载图片报错

======== Exception caught by image resource service ================================================
The following assertion was thrown resolving an image codec:
'package:flutter/src/painting/binding.dart': Failed assertion: line 103 pos 12: 'cacheHeight == null || cacheHeight > 0': is not true.

Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
https://github.com/flutter/flutter/issues/new?template=2_bug.md

When the exception was thrown, this was the stack:
#2 PaintingBinding.instantiateImageCodec (package:flutter/src/painting/binding.dart:103:12)
#3 ResizeImage.load.decodeResize (package:flutter/src/painting/image_provider.dart:769:20)
#4 CachedNetworkImage._loadImage (package:kraken/src/painting/cached_network_image.dart:66:20)

(elided 2 frames from class _AssertionError)
Image provider: CachedNetworkImage()
Image key: CachedNetworkImage()

Copy link
Member

@wssgcg1213 wssgcg1213 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要恢复 naturalWidth/Height 的实现

@andycall
Copy link
Member Author

需要恢复 naturalWidth/Height 的实现

done

@yuanyan
Copy link
Contributor

yuanyan commented Dec 1, 2021

CI 没有通过

import 'dart:io';
import 'dart:ui';
import 'dart:typed_data';

import 'package:flutter/cupertino.dart';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

上面这个 import 有点问题, 不知道啥时候引入的

}

int naturalWidth = 0;
int naturalHeight = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

做成没有 setter 会好一点, 这样貌似可以外部修改

// load again, but still update the image cache with LRU information.
if (stream.completer != null) {
final ImageStreamCompleter? completer =
PaintingBinding.instance!.imageCache!.putIfAbsent(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里不用换行的

Copy link
Member

@wssgcg1213 wssgcg1213 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No logical problems.

@answershuto answershuto merged commit 129f347 into main Dec 6, 2021
@answershuto answershuto deleted the feat/image-optimize branch December 6, 2021 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

使用 ResizeImage 来降低图片的绘制成本
5 participants