• 0

Update multiple <canvas> at different sizes


Question

Can someone help me with a little bit of JavaScript?

 

Have a look at the attached image, I have a <canvas> element called "pic_256", that has a Picture that I've populated. I'd also like to add the same picture to the two other canvases, Each at different sizes, one at 128*128 and the other one at 64*64.  Is there an easy way to update the other canvas elements ("pic_128" and "pic_64")with a smaller version of the original canvas ("pic_256")?


Artboard.thumb.png.47c27e22b3fbc70f1b48d56ec41f6f3a.png

 

 

Link to comment
https://www.neowin.net/forum/topic/1405195-update-multiple-at-different-sizes/
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Maybe by getting the canvas context into a variable    var destcontext = dest.getContext('2d');

and then doing a drawImage    ctx = dest       "image" = source

 

void ctx.drawImage(image, dx, dy);

void ctx.drawImage(image, dx, dy, dWidth, dHeight);

void ctx.drawImage(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight);

 

https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/drawImage

  • Like 1
  • 0

you might try different solutions...

 

ctx.imageSmoothingEnabled = false || true   (true is default)

ctx.imageSmoothingQuality = "low" || "medium" || "high"

 

or css

image-rendering: auto;

image-rendering: crisp-edges;

image-rendering: pixelated;

image-rendering: smooth;

 

Here are also 2 different solutions.  One is with filters, and one is with resizing in multiple steps instead one step.

https://stackoverflow.com/questions/17861447/html5-canvas-drawimage-how-to-apply-antialiasing

Here is a multistep solution also

https://stackoverflow.com/questions/18922880/html5-canvas-resize-downscale-image-high-quality

 

Please tell me which version worked for you 😃

  • 0

FANTTASTIC!!!!

Thank you so much.  The CSS version did not work for me but the canvas context method worked.

 

 

 

  On 21/02/2021 at 19:48, sorlag said:

you might try different solutions...

 

ctx.imageSmoothingEnabled = false || true   (true is default)

ctx.imageSmoothingQuality = "low" || "medium" || "high"

 

or css

image-rendering: auto;

image-rendering: crisp-edges;

image-rendering: pixelated;

image-rendering: smooth;

 

Here are also 2 different solutions.  One is with filters, and one is with resizing in multiple steps instead one step.

https://stackoverflow.com/questions/17861447/html5-canvas-drawimage-how-to-apply-antialiasing

Here is a multistep solution also

https://stackoverflow.com/questions/18922880/html5-canvas-resize-downscale-image-high-quality

 

Please tell me which version worked for you 😃

Expand  

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Posts

    • Jeez 4 years and its still garbage at least W10 saw some usability improvements
    • WoW as primary game.  Thought bitcraft looks interesting and comes to EA shortly. 
    • I’m so glad to see the direction this political image thread has gone. 
    • Explorer patcher is a free alternative that also works great. I get that you use startisback it’s more for others that see this and are curious.
    • PeaZip 10.5.0 by Razvan Serea PeaZip is an open source file and archive manager. It's freeware and free of charge for any use. PeaZip can extract most of archive formats both from Windows and Unix worlds, ranging from mainstream 7Z, RAR, TAR and ZIP to experimental ones like PAQ/LPAQ family, currently the most powerful compressor available. Open and extract 200+ archive formats: 001, 7Z, ACE(*), ARC, ARJ, BZ2, CAB, DMG, GZ, ISO, LHA, PAQ, PEA, RAR, TAR, UDF, WIM, XZ, ZIP ZIPX - view full list of supported archive file formats for archiving and for extraction. PeaZip provides fast, high compression ratio multi-format archiving - view file compression and decompression benchmarks for more information. PeaZip is localized in 29 languages and is capable of handling all most popular archive formats (180+ file types), supporting a wide array of advanced file and archive management features (search, bookmarks, thumbnail viewer, find duplicate files and compute hash/checksum value, convert archive files...), especially focused on security (strong encryption, two factor authentication, encrypted password manager, secure file deletion...). PeaZip 10.5.0 release notes: PeaZip 10.5.0 brings a major update in the file manager, boosting archive browsing performances, improving archive editing, adding new functions to open file as archive from within archives, to prevent running a custom list of file extensions without confirmation, and to hide or show hidden files. On macOS all file browser styles and icon sizes are now available as on other platforms. On Windows it is now possible to explore NTFS Alternate Data Streams to gather additional information on files, including a dedicated tools to batch scan the input for Zone.Identifier (Mark of The Web) to detect files coming from remote systems. In addition, the option to include the Zone.Identifier metadata in archives is now enabled by default for all formats supporting it (RAR, WIM). Backend were updated to Pea 1.25. Full list of changes and fixes is available at https://peazip.github.io/changelog.html Download: PeaZip 64-bit | PeaZip Portable 64-bit | ~13.0 MB (Open Source) Download: PeaZip 32-bit | PeaZip Portable 32-bit View: PeaZip Home Page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • One Month Later
      jezzzy earned a badge
      One Month Later
    • First Post
      CSpera earned a badge
      First Post
    • One Month Later
      MIR JOHNNY BLAZE earned a badge
      One Month Later
    • Apprentice
      Wireless wookie went up a rank
      Apprentice
    • Week One Done
      bukro earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      624
    2. 2
      ATLien_0
      280
    3. 3
      +FloatingFatMan
      179
    4. 4
      Michael Scrip
      149
    5. 5
      Steven P.
      118
  • Tell a friend

    Love Neowin? Tell a friend!