floyd-steinberg-dithering/web/main.dart
2018-02-14 15:56:55 +01:00

31 lines
No EOL
778 B
Dart

import 'dart:html';
import 'package:dart_floyd_steinberg_dithering/Dither.dart';
CanvasElement input;
CanvasElement output;
ImageElement inputImg;
ImageElement outputImg;
void main() {
inputImg = new ImageElement(src: 'kitten.jpg', width: 712, height: 470);
input = document.querySelector('#input');
output = document.querySelector('#output');
inputImg.onLoad.listen(imgLoaded);
}
void imgLoaded(Event e) {
print("image loaded");
input.context2D.drawImage(inputImg, 0, 0);
PixelArray px = new PixelArray.fromImageData(getImageData(input), 712);
px = Pixed.greyscale(px);
output.context2D.putImageData(px.toImageData(), 0, 0);
}
ImageData getImageData(CanvasElement canvas) {
return canvas.context2D.getImageData(0, 0, canvas.width, canvas.height);
}