import 'dart:html';
import 'package:image/image.dart';
CanvasElement input;
CanvasElement output;
ImageElement inputImg;
void main() {
inputImg = new ImageElement(src: 'kitten.jpg', width: 712, height: 470);
input = document.querySelector('#input');
print(input);
inputImg.onLoad.listen(imgLoaded);
output = document.querySelector('#output');
output.context2D.fillRect(0, 0, output.width, output.height);
}
void imgLoaded(Event e) {
print("image loaded");
input.context2D.drawImage(inputImg, 0, 0);
Image outputImg = editImage( getImageFromCanvas(input) );
drawImageToCanvas(output, outputImg ) ;
}
Image getImageFromCanvas(CanvasElement input) {
ImageData data = input.context2D.getImageData(0, 0, input.width, input.height);
return new Image.fromBytes(input.width, input.height, data.data);
}
void drawImageToCanvas(CanvasElement canvas, Image image) {
var imageData = canvas.context2D.createImageData(image.width, image.height);
imageData.data.setRange(0, imageData.data.length, image.getBytes());
canvas.context2D.putImageData(imageData, 0, 0);
}
Image editImage(Image image) {
image = contrast( image, 200);
for (var y = 0; y < image.height; y++) {
for (var x = 0; x < image.width; x++) {
// print(image.getPixel(x, y));
}
}
return image;
}