Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8314171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:43:58+00:00 2026-06-08T20:43:58+00:00

f I have a ContentControl… and its Content is set to a custom Image…

  • 0

f I have a ContentControl… and its Content is set to a custom Image… and the custom Image has field called Source that holds Bitmap data… what extra steps do I need to make sure the ContentControl displays that bitmap data? I’m thinking I did this step wrong though… because Source is just a field?

Also, the bitmap data changes constantly.

public class VideoRenderer : System.Windows.Controls.Image
{
    #region Fields
    protected DateTime lastFrameTimestamp;
    protected Rectangle rect;
    protected System.Timers.Timer timer;
    protected BitmapData bitmapData;
    protected Bitmap bitmap = null;
    private Video videoObject = null;
    private Participant participantObject = null;
    private bool isRunning = false;
    private int updateInterval = 50;
    private uint key = 0;
    private int videoWidth = 0;
    private int videoHeight = 0;
    private SkypeRoot skypeRef;
    private FrameTransport frameTransport;
    private double fps = 0;
    private System.Windows.Media.ImageSource source;
    object bitmapLock = new object();
    #endregion


    /// <summary>
    /// Gets and sets the source of the video renderer image.
    /// </summary>
    public new System.Windows.Media.ImageSource Source
    {
        get { return source; }
        set { source = value; }
    }


    #region Constructors
    /// <summary>
    /// Constructor.
    /// </summary>
    /// <param name="skype"></param>
    public VideoRenderer(SkypeRoot skype)
    {
        this.skypeRef = skype;
    }
    #endregion


    #region Internal Members
    /// <summary>
    /// Convert frame to a bitmap.
    /// </summary>
    /// <returns></returns>
    internal bool MoveFrameToBitmap()
    {
        lock (bitmapLock)
        {
            if (frameTransport.bitmapDataSize == 0)
            {
                return false;
            }

            bool ResolutionHasChanged = ((videoWidth != frameTransport.width) | (videoHeight != frameTransport.height));

            if ((bitmap == null) | ResolutionHasChanged)
            {
                if (bitmap != null)
                {
                    bitmap.Dispose();
                }

                videoHeight = frameTransport.height;
                videoWidth = frameTransport.width;
                bitmapData = null;
                bitmap = new Bitmap(videoWidth, videoHeight);
                bitmapData = new BitmapData();
                bitmapData.Width = videoWidth;
                bitmapData.Height = videoHeight;
                bitmapData.PixelFormat = System.Drawing.Imaging.PixelFormat.Format24bppRgb;
                rect = new Rectangle(0, 0, videoWidth, videoHeight);
            }

            bitmap.LockBits(rect, ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb, bitmapData);
            IntPtr ptr = bitmapData.Scan0;
            Marshal.Copy(frameTransport.bitmapData, 0, ptr, frameTransport.bitmapDataSize);
            bitmap.UnlockBits(bitmapData);

            if (ResolutionHasChanged) skypeRef.events.FireOnVideoResolutionChanged(this, new RootEvents.OnVideoResolutionChangedArgs(videoWidth, videoHeight));

            return true;
        }
    }

    /// <summary>
    /// Draw the bitmap to the picturebox.
    /// </summary>
    internal void DrawBitmap()
    {
        lock (bitmapLock)
        {
            using (MemoryStream memory = new MemoryStream())
            {
                bitmap.Save(memory, ImageFormat.Png);
                memory.Position = 0;
                BitmapImage bitmapImage = new BitmapImage();
                bitmapImage.BeginInit();
                bitmapImage.StreamSource = memory;
                bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
                bitmapImage.EndInit();

                source = bitmapImage;
            }
        }
    }
    #endregion


    #region External Members
    /// <summary>
    /// Start the video rendering.
    /// </summary>
    public void Start()
    {
        if (isRunning)
        {
            return;
        }

        if (videoObject == null)
        {
            throw new Exception("Error: cannot start rendering when the associated video object is null.");
        }

        isRunning = true;
        frameTransport = new FrameTransport();

        timer = new System.Timers.Timer();
        timer.Interval = updateInterval;
        timer.Enabled = false;
        timer.Elapsed += TimerTick;

        Int32[] preferences = new Int32[1];
        preferences[0] = MakeFourCC('B', 'I', '2', '4');
        frameTransport.SetPreferences(1, preferences);
        key = frameTransport.Key();
        videoObject.SetRemoteRendererID(key);
        lastFrameTimestamp = DateTime.Now;
        timer.Start();
    }
    #endregion


    #region Events
    /// <summary>
    /// Handle the timer when video is running.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void TimerTick(object sender, EventArgs e)
    {
        if (frameTransport.IsNewFrameAvailable())
        {
            bool frameOk = frameTransport.GetFrame();

            if (frameOk)
            {
                bool bitmapOk = MoveFrameToBitmap();

                if (bitmapOk)
                {
                    AddCustomGraphics();
                    DrawBitmap();
                    double msSinceLastFrame = (Int32)DateTime.Now.Subtract(lastFrameTimestamp).TotalMilliseconds;
                    fps = 1000 / msSinceLastFrame;
                    lastFrameTimestamp = DateTime.Now;
                }
            }
        }
    }
    #endregion
}

Cheers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T20:43:59+00:00Added an answer on June 8, 2026 at 8:43 pm

    This issue was how the ImageSource was set up… creating a non overloaded Source property was the issue… renaming this and then setting that property to the inherited source fixed the issue.

    Cheers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ContentControl and its content is a custom FrameworkElement. FrameworkElement has only
I have custom ContentControl called TabItem public class TabItem : ContentControl I have set
I have an MVVM setup with a mainwindow that contains a ContentControl. I set
I have a window that has a StackPanel, and the StackPanel has a ContentControl,
I have a WPF page that has 2 ContentControls on it. Both of the
In my Silverlight 4 application, I have a ContentControl with its ContentTemplate property bound
I have an application that has a top level navigation menu which consists of
Say I have the following code: ContentControl c = new ContentControl(); c.SetBinding (ContentControl.Content, new
I have this very simple XAML window: <Grid> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition/> </Grid.RowDefinitions> <ContentControl Content={Binding
I have an MVVM Silverlight 4 application that holds a list of modules (a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.