floyd-steinberg-dithering/web/main.dart

31 lines
778 B
Dart
Raw Permalink Normal View History

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