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

  • SEARCH
  • Home
  • 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 8675139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:52:45+00:00 2026-06-12T19:52:45+00:00

Possible Duplicate: How to render bitmap into canvas in WPF? What I want is

  • 0

Possible Duplicate:
How to render bitmap into canvas in WPF?

What I want is simple. I want to place a BitmapImage into a Canvas in C#. My app is based on WPF. I searched for this and I found similar questions, but I could not find what I’m looking for.

In short, I have this:

BitmapImage img = new BitmapImage(new Uri("c:\\xyz.jpg"));

And I want to put this in the canvas, the mean is not that important, it can be a rectangle or whatever.

  • 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-12T19:52:46+00:00Added an answer on June 12, 2026 at 7:52 pm

    A BitmapImage object cannot be positioned inside a Canvas because it’s not a control. What you can do is to derive your own class from the Canvas and override the OnRender() method to draw your bitmap. Basically something like this:

    class CanvasWithBitmap : Canvas
    {
        public CanvasWithBitmap()
        {
            _image = new BitmapImage(new Uri(@"c:\xyz.jpg"));
        }
    
        protected override void OnRender(DrawingContext dc)
        {
            dc.DrawImage(_image,
                new Rect(0, 0, _image.PixelWidth, _image.PixelHeight));
        }
    
        private BitmapImage _image;
    }
    

    Of course you may need to expose the file path and coordinates inside the Canvas through properties. If you do not want to declare your own class just to draw a bitmap then you can’t use the BitmapImage class directly. The control to display images is Image, let’s try this:

    BitmapImage bitmap = new BitmapImage();
    bitmap.BeginInit();
    bitmap.UriSource = new Uri(@"c:\xyz.jpg");
    bitmap.EndInit();
    
    Image image = new Image();
    image.Source = bitmap;
    

    Now you can put the Image control where you want inside the Canvas.

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

Sidebar

Related Questions

Possible Duplicate: jquery .text doesn’t render HTML elements into the DOM I have an
Possible Duplicate: How to render a plugin added dynamically? This is my code :
Possible Duplicate: Reference assignment operator in php =& i want to create a blog,this
Possible Duplicate: How to render PDF in Android My question is just simple. which
Possible Duplicate: Is there any way to render text into DirectWrite???? Hello, all is
Possible Duplicate: How to Connect External NFC Card Reader to Tablet(Android 2.3.3) This is
Possible Duplicate: How can I convert a list<> to a multi-dimensional array? I want
Possible Duplicate: How to do the vector of sets in C++? I want to
Possible Duplicate: How can I understand nested ?: operators in PHP? Why does this:
Possible Duplicate: Can main function call itself in C++? I found this problem very

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.