如何将TIF图像加载到Flutter Web中?

发布于 2025-01-24 10:40:34 字数 79 浏览 3 评论 0原文

如何将.tif映像读取为图像小部件的颤音中的图像?

由于默认情况下不支持TIF,因此有任何可以加载和解码TIF图像的软件包或方法?

How can i read a .tif image as a Image widget in flutter?

Since tif is not supported by default in flutter, there is any package or method that can load and decode a tif image?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

眼眸 2025-01-31 10:40:34

一段时间以前看到了这种问题...

您可以解码图像并将其编码为PNG,

import 'package:image/image.dart' as imgLib;
imgLib.Decoder dec = imgLib.findDecoderForData(response.data);
Image.memory(imgLib.encodePng(dec.decodeImage(response.data)))

然后像您可以在图像中显示PNG一样。

干杯!!

Saw this kind of question some time ago...

You can decode the image and encode it as png like

import 'package:image/image.dart' as imgLib;
imgLib.Decoder dec = imgLib.findDecoderForData(response.data);
Image.memory(imgLib.encodePng(dec.decodeImage(response.data)))

You can then display the png in Image.

Cheers!!

清君侧 2025-01-31 10:40:34

如果响应数据是字符串,则此代码段适合我

import 'package:image/image.dart' as imgLib;
final dec = imgLib.findDecoderForData(base64Decode(url));
Image.memory(
              Uint8List.fromList(
                  imgLib.encodeJpg(dec!.decodeImage(base64Decode(url))!)),
            )

If the response data is String, this code snippet work for me

import 'package:image/image.dart' as imgLib;
final dec = imgLib.findDecoderForData(base64Decode(url));
Image.memory(
              Uint8List.fromList(
                  imgLib.encodeJpg(dec!.decodeImage(base64Decode(url))!)),
            )
榕城若虚 2025-01-31 10:40:34

您可以使用图像包进行。

import 'package:image/image.dart' as imgLib;

//use this to load the tiff file based on the file path
await imgLib.decodeTiffFile('assets/test.tif');

但是,当我使用上述方法时,它不断提及不存在文件路径。因此,我更改了一些方法,并使用了以下方法。

import 'package:flutter/services.dart';
import 'package:image/image.dart' as imgLib;

final filePath = 'assets/test.tif';
final data = await rootBundle.load(filePath);
Uint8List audioUint8List = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
final map = await imgLib.decodeTiff(audioUint8List); 

我必须使用root Bundle读取文件,将其转换为UINT8LIST,因为DECODE函数仅读取UINT8LIST,然后用函数解码读取它。

希望它有帮助。

You can use the image package to do it.

import 'package:image/image.dart' as imgLib;

//use this to load the tiff file based on the file path
await imgLib.decodeTiffFile('assets/test.tif');

But when I used the above method, it keep mentioning that the file path does not exist. So, I changed a bit and used the following method.

import 'package:flutter/services.dart';
import 'package:image/image.dart' as imgLib;

final filePath = 'assets/test.tif';
final data = await rootBundle.load(filePath);
Uint8List audioUint8List = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
final map = await imgLib.decodeTiff(audioUint8List); 

I have to read the file using root bundle, converting it to Uint8List as decode function only read Uint8List, then read it with the function decodeTiff.

Hope it helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文