Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

HTML5 - Sampling color from hidden image/video

New Here ,
May 31, 2017 May 31, 2017

I have a setup of two images, one in front of the other. When the user clicks on the front image I want to sample the same pixel in the background image.

In Actionscript 3 i used the bitmapData class to do this.

In the HTML5 document I can get the pixel color of the entire canvas but only the visible pixels. Is there a way to sample the image in the background that is not visible on the canvas? Maybe create a second context for the other image? Preferably without flipping images.

674
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 31, 2017 May 31, 2017
Translate
Community Expert ,
May 31, 2017 May 31, 2017
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 31, 2017 May 31, 2017

"Document" does not exist in Adobe Animate CC.  Is there a way to reference it?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 31, 2017 May 31, 2017

document

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 31, 2017 May 31, 2017

Super sorry, it autocapitalized for some reason.  I was having difficulty as document was returning null until i realized i happened to have generated some poorly thought out variables further up.  Thanks very much.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 31, 2017 May 31, 2017

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 31, 2017 May 31, 2017

Oh if you don't mind, is the getElementById only for retrieving something from the server?  I can't seem to load an image from the library this way and using lib.ImageName  does not produce a format usable in getImageData.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 31, 2017 May 31, 2017

rymbrant  wrote

Oh if you don't mind, is the getElementById only for retrieving something from the server?

Eh? getElementById() isn't ever for that. It's used for retrieving references to elements in the currently loaded HTML document that have been assigned ID attributes... and it doesn't have anything to do with Animate Canvas programming.

To do what you want in a Canvas document, you have to assign your bitmap a linkage name in the library (double-click next to it in the Linkage column), load into a secondary offscreen canvas, then use getImageData() on it. Like this:

// setup

var myBitmap = new lib.myImage;

var bounds = myBitmap.getBounds();

myBitmap.cache(0, 0, bounds.width, bounds.height);

window.myBitmapContext = myBitmap.cacheCanvas.getContext("2d");

// usage (x, y, width, height; returns r, g, b array)

myBitmapContext.getImageData(0, 0, 1, 1).data;

I stored the bitmap context to a global (window) variable so you can access it from anywhere without having to worry about scope.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 31, 2017 May 31, 2017
LATEST

Oh thank you so much.  So much info online is crazy out of date and i was missing a couple of very basic bits of info that you have supplied.  Now many things make sense.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines