Project

General

Profile

Displaying Wimage as a video

Added by Yannick Lohrmann almost 5 years ago

Hi all,

I am currently creating a Wt web application where I want to show Wimages in such a way that it looks like a video.

Rigth now every time I update the image you can see it flick between the images. ( I guess Wt first deletes first Wimage and then loads new Image)

I think the solution will be uploading the next image in the background, I tried this using WStackWidget but this doesn't seem to work since it has the same output.

The last solution is trying to create a video-stream from the images and display this using WVideo or Wmediaplayer but since the images don't come on frequent times I don't know if this is the right solution.

Anyone has sugggestions how to accomplish this ?

Thanks


Replies (1)

RE: Displaying Wimage as a video - Added by Wim Dumon almost 5 years ago

Hey Yannick,

The issue is that the browser clears the image when you set the new URL, until the new image is received. We once made this, based on the principle below, where a WResource was used that blocks until the next image is available (other variations may apply to your scheme):

MJPEGWidget::MJPEGWidget(WContainerWidget *parent)
  : WContainerWidget(parent),
    mjpeg1_(0),
    i_(0)
{
  image1_ = new WImage(WLink(), "Device unavailable", this);
  image2_ = new WImage(WLink(), "Device unavailable", this);
  image2_->setHidden(true);
  image1_->setMaximumSize("100%", "100%");
  image2_->setMaximumSize("100%", "100%");

  image1_->imageError().connect(boost::bind(&MJPEGWidget::imageLoaded,
                                            this,
                                            image1_,
                                            image2_));
  image1_->imageLoaded().connect(boost::bind(&MJPEGWidget::imageLoaded,
                                             this,
                                             image1_,
                                             image2_));
  image2_->imageError().connect(boost::bind(&MJPEGWidget::imageLoaded,
                                            this,
                                             image2_,
                                             image1_));
  image2_->imageLoaded().connect(boost::bind(&MJPEGWidget::imageLoaded,
                                             this,
                                             image2_,
                                             image1_));
}

void MJPEGWidget::imageLoaded(WImage* img, WImage* other)
{
  img  ->setHidden(false);
  other->setHidden(true);
  std::stringstream ss;
  ss << ++i_;
  other->setImageLink(WLink(mjpeg1_->url() + "&image=" + ss.str()));
}

void MJPEGWidget::setResource(MJPEGResource* resource)
{
  assert(!mjpeg1_ && resource);

  mjpeg1_ = resource;
  std::stringstream ss;
  ss << ++i_;
  image1_->setImageLink(mjpeg1_->url() + "&image=" + ss.str());
}
    (1-1/1)