Remove Pointers to Image Lib

This commit is contained in:
Unknown 2018-02-12 15:55:45 +01:00
parent 758503d33f
commit 60f5ce3cc1
4 changed files with 27 additions and 35 deletions

18
lib/Dither.dart Normal file
View file

@ -0,0 +1,18 @@
import 'dart:html';
class Dither {
static ImageData editImage(ImageData 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;
}
}

3
lib/dither.dart Normal file
View file

@ -0,0 +1,3 @@
library dither;
export 'Dither.dart';

View file

@ -8,7 +8,6 @@ environment:
sdk: '>=1.20.1 <2.0.0' sdk: '>=1.20.1 <2.0.0'
dependencies: dependencies:
image: "^1.1.29"
# path: ^1.4.1 # path: ^1.4.1
dev_dependencies: dev_dependencies:

View file

@ -1,56 +1,28 @@
import 'dart:html'; import 'dart:html';
import 'package:image/image.dart'; import 'package:dart_floyd_steinberg_dithering/Dither.dart';
CanvasElement input; CanvasElement input;
CanvasElement output; CanvasElement output;
ImageElement inputImg; ImageElement inputImg;
ImageElement outputImg;
void main() { void main() {
inputImg = new ImageElement(src: 'kitten.jpg', width: 712, height: 470); inputImg = new ImageElement(src: 'kitten.jpg', width: 712, height: 470);
input = document.querySelector('#input'); input = document.querySelector('#input');
print(input);
inputImg.onLoad.listen(imgLoaded);
output = document.querySelector('#output'); output = document.querySelector('#output');
output.context2D.fillRect(0, 0, output.width, output.height); inputImg.onLoad.listen(imgLoaded);
} }
void imgLoaded(Event e) { void imgLoaded(Event e) {
print("image loaded"); print("image loaded");
input.context2D.drawImage(inputImg, 0, 0); input.context2D.drawImage(inputImg, 0, 0);
Image outputImg = editImage( getImageFromCanvas(input) ); output.context2D.putImageData( Dither.editImage( getImageData(input)), 0, 0);
drawImageToCanvas(output, outputImg ) ;
} }
Image getImageFromCanvas(CanvasElement input) { ImageData getImageData(CanvasElement canvas) {
ImageData data = input.context2D.getImageData(0, 0, input.width, input.height); return canvas.context2D.getImageData(0, 0, canvas.width, canvas.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;
} }