1

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 Answers1

1

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.

andy.xyz
  • 2,567
  • 1
  • 13
  • 18
  • Tried this, unfortunately it's not working. I get `2022/07/18 20:04:13 Cause: failed to decode image: image: unknown format 2022/07/18 20:04:13 At: /Users/michalporeda/go/pkg/mod/fyne.io/fyne/v2@v2.2.3/internal/painter/image.go:56 ` error. Problem is that this byte array doesn't have any headers related to any file format. That's why I need some way to transform incoming bytes into complete image :/ – Michał Poreda Jul 18 '22 at 18:04
  • If you are doing more complex image processing you will have to take the first option and process it into an in-memory image that Fyne can render, using `canvas.NewImageFromImage` – andy.xyz Jul 19 '22 at 01:40
  • Yes I know, and that's what my original question was about. How to make image from these bytes – Michał Poreda Jul 19 '22 at 12:14