沈斌
2017-12-15 f9b157566af34b8dc28ba10b34d025ac04f3168b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { Component, ViewChild } from '@angular/core';
import { Bounds, CropperSettings, ImageCropperComponent } from 'ng2-img-cropper';
 
@Component({
    selector: 'app-cropper',
    templateUrl: './cropper.component.html'
})
export class CropperComponent {
    name: string;
    data1: any;
    cropperSettings: CropperSettings;
 
    @ViewChild('cropper', undefined) cropper: ImageCropperComponent;
 
    constructor() {
        this.name = 'ng-alain';
        this.cropperSettings = new CropperSettings();
 
        this.cropperSettings.noFileInput = true;
 
        this.cropperSettings.width = 200;
        this.cropperSettings.height = 200;
 
        this.cropperSettings.croppedWidth = 200;
        this.cropperSettings.croppedHeight = 200;
 
        this.cropperSettings.canvasWidth = 460;
        this.cropperSettings.canvasHeight = 400;
 
        this.cropperSettings.minWidth = 100;
        this.cropperSettings.minHeight = 100;
 
        this.cropperSettings.cropperDrawSettings.strokeColor = 'rgba(255,255,255,1)';
        this.cropperSettings.cropperDrawSettings.strokeWidth = 2;
 
        this.cropperSettings.rounded = false;
 
        this.data1 = {};
    }
 
    cropped(bounds: Bounds) {
        console.log(bounds);
    }
 
    fileChange($event) {
        const image: any = new Image();
        const file: File = $event.target.files[0];
        const myReader: FileReader = new FileReader();
        const that = this;
        myReader.onloadend = (loadEvent: any) => {
            image.src = loadEvent.target.result;
            that.cropper.setImage(image);
        };
 
        myReader.readAsDataURL(file);
    }
}