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 7662741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:52:42+00:00 2026-05-31T13:52:42+00:00

I would like to show an image on Canvas(HTML5) so that I will be

  • 0

I would like to show an image on Canvas(HTML5) so that I will be able to drag’n’drop it later. This is how i started, I am using a circle shape, which is being drawn on the Canvas, then i want its background texture be an image defined externally of this pasted code.
Now i have that the texture/image is being drawn at x=0, y=0 location. Since i must use ‘no-repeat’ argument for createPattern() method (picture will be enabled for drag’n’drop), so i must create pattern at the location circle.x, circle.y (these are changed on drag’n’drop). How can I make pattern be drawn at location, which is not (0, 0); ?

If you are aware of any better solution, then i am open for proposals

It is said that a picture says thousand words, so on the picture i would explain it as such:

enter image description here

    var ctx, circle;

    function draw(){    
       ctx.clearRect(0, 0, canvas.width, canvas.height);
       ctx.beginPath();                 
       ctx.arc(circle.x+imageObj.width/2,circle.y+imageObj.height/2,circle.r,0,Math.PI*2,false);
       var pattern = ctx.createPattern(imageObj, 'no-repeat');   
       ctx.fillStyle = pattern;
       ctx.fillRect(circle.x,circle.y, imageObj.width, imageObj.height);
    }


window.onload = function(){
    canvas = document.getElementById('area');
    ctx = canvas.getContext('2d');

    circle = {
        x: canvas.width/2,
        y: canvas.height/2,
        r: 50
    }

    draw();     
}; 
  • 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-05-31T13:52:43+00:00Added an answer on May 31, 2026 at 1:52 pm

    Ok, i found a way, which does what I want. If you guys know of any other way, please submit your answers

        var ctx, circle;
    
            function draw(){    
               ctx.clearRect(0, 0, canvas.width, canvas.height);
               ctx.beginPath();                 
               ctx.arc(circle.x+imageObj.width/2,circle.y+imageObj.height/2,circle.r,0,Math.PI*2,false);
               ctx.drawImage(imageObj, circle.x, circle.y, imageObj.width, imageObj.height);
            }
    
    
        window.onload = function(){
            canvas = document.getElementById('area');
            ctx = canvas.getContext('2d');
    
            circle = {
                x: canvas.width/2,
                y: canvas.height/2,
                r: 50
            }
    
            draw();     
        }; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using blogengine.net. I would like to show a default image in the H1
I have an image that I would like to show in full regardless of
I would like to make an addon to browser, that would show image of
I have a custom WPF Canvas, upon which I would like to show a
I would like to show 10 elements (images) incrementally. When the 9th image is
I would like to show an image background when my UITableView is empty. Currently
I would like to show an image on a screen, and it's size (Height
I have an image that is 480 pixels by 40 pixels. I would like
I am using a custom title view and would like to show/hide a progressbar
I would like to show an image link (image is on my server) in

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.