Answer the question
In order to leave comments, you need to log in
How to make an image b/w?
I have a color image in the storage (localStorage.getItem('saveImage')) and I need to take a photo from the storage and make it black and white.
In the example localStorage.getItem('saveImage') THIS is " https://images.unsplash.com/photo-1568097379042-34... "
function drawImageOnCanvas(size, reduct, reductPixel) {
canvas.width = size;
canvas.height = size;
const colorImage = localStorage.getItem('saveImage'); <---------------- цветное изображение
const img = new Image();
img.crossOrigin = 'Anonymous';
img.src = ЗДЕСЬ ЛИНК ДОЛЖЕН БЫТЬ НА ЧЕРНО-БЕЛОЕ ИЗОБРАЖЕНИЕ
img.onload = () => {
ctx.drawImage(img, 0, 0, size, size);
};
canvasSize = size;
reductionNumber = reduct;
reductionPixelNumber = reductPixel;
}
Answer the question
In order to leave comments, you need to log in
function drawImageOnCanvas(size, reduct, reductPixel) {
canvas.width = size;
canvas.height = size;
const colorImage = localStorage.getItem('saveImage');/// <---------------- цветное изображение
ctx.drawImage(colorImage, 0, 0, size, size);
ctx.globalCompositeOperation='color';
ctx.fillStyle = "white";
ctx.globalAlpha = 1;
ctx.fillRect(0, 0, size,size);
canvasSize = size;
reductionNumber = reduct;
reductionPixelNumber = reductPixel;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question