如何从随机字节数组中获取图像

huangapple go评论84阅读模式
英文:

How to get image from random byte array

问题

我正在使用解码器与原本使用WebRTC和HTML视频作为显示的Apple CarPlay进行工作。我正在尝试用Fyne图像刷新替换HTML。

当前的源代码如下:

duration := time.Duration((float32(1) / float32(fps)) * float32(time.Second))

if videoTrack != nil {
	videoTrack.WriteSample(media.Sample{Data: data.Data, Duration: duration})
}

其中videoTrack是:

videoTrack       *webrtc.TrackLocalStaticSample

我尝试将data.Data(因为它是byte[])移入图像转换器,但我猜还需要做更多的工作。

我正在寻求一些帮助,将这些byte[]转换为图像压缩,因为这是Fyne使用的格式,但一直没有成功。有人可以给我一些提示吗?

英文:

I'm working with decoder for Apple CarPlay which originally is using WebRTC and html video as display for it. I'm trying to replace html with Fyne image refresh.

Current source code looks like that

duration := time.Duration((float32(1) / float32(fps)) * float32(time.Second))

if videoTrack != nil {
	videoTrack.WriteSample(media.Sample{Data: data.Data, Duration: duration})
}

where videoTrack is:

videoTrack       *webrtc.TrackLocalStaticSample

I've tried to move data.Data (since it's byte[]) into image converter, but I guess there's some more for that.

Im looking for some help in transporting these byte[] into image compression because that's the format Fyne is using, but without any success. Can anyone give me some hint in that?

答案1

得分: 1

你可以使用标准的Go image包将byte[]加载为图像(阻塞操作),或者将其作为资源传递给Fyne。要进行后者,请尝试使用canvas.NewImageFromResource(fyne.NewStaticResource("streamName.png", data))

设置完成后,你可以将ImageResource设置为你的图像,并调用Refresh()来更新显示。

英文:

You can either load the byte[] to an image using standard go image package (blocking operation) or you can pass it to Fyne as a resource).
To do the latter try canvas.NewImageFromResource(fyne.NewStaticResource(“streamName.png”, data)).

After this setup you can set the Image or Resource on your image and call 'Refresh()` to update the display.

huangapple
  • 本文由 发表于 2022年7月18日 00:04:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/73013327.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定