How to scale an imageData in HTML canvas?

You could draw the imageData to a new canvas, scale the original canvas and then draw the new canvas to the original canvas. Something like this should work: var imageData = context.getImageData(0, 0, 100, 100); var newCanvas = $(“<canvas>”) .attr(“width”, imageData.width) .attr(“height”, imageData.height)[0]; newCanvas.getContext(“2d”).putImageData(imageData, 0, 0); context.scale(1.5, 1.5); context.drawImage(newCanvas, 0, 0); Here’s a functioning demo … Read more

Is canvas getImageData method machine/browser dependent?

Yes. This fact is exploited by canvas fingerprinting: The same HTML5 Canvas element can produce exceptional pixels on a different web browsers, depending on the system on which it was executed. This happens for several reasons: at the image format level — web browsers uses different image processing engines, export options, compression level, final images … Read more

Android get image from gallery into ImageView

Simple pass Intent first: Intent i = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(i, RESULT_LOAD_IMAGE); And you will get picture path on your onActivityResult: @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) { Uri selectedImage = data.getData(); String[] filePathColumn = { MediaStore.Images.Media.DATA … Read more

Get pixel color from canvas, on mousemove

Here’s a complete, self-contained example. First, use the following HTML: <canvas id=”example” width=”200″ height=”60″></canvas> <div id=”status”></div> Then put some squares on the canvas with random background colors: var example = document.getElementById(‘example’); var context = example.getContext(‘2d’); context.fillStyle = randomColor(); context.fillRect(0, 0, 50, 50); context.fillStyle = randomColor(); context.fillRect(55, 0, 50, 50); context.fillStyle = randomColor(); context.fillRect(110, 0, 50, … Read more