日期:2014-05-16  浏览次数:20342 次

求帮忙分析一下JS代码
主要功能是将9.PNG图片格式转换成64位的字符串,我要将这个功能写到winfrom里
function Walker() {
    this.segments = [];
    this.currentSegment = null;
    this.i = -1;
};

Walker.prototype.step = function (alpha) {
    this.i ++;
    if (!this.currentSegment || this.currentSegment.alpha != alpha) {
        this.currentSegment = {
            start: this.i,
            end: this.i,
            alpha: alpha
        };
        
        this.segments.push(this.currentSegment);
    } else {
        this.currentSegment.end = this.i;
    }
};

var NinePatch = {};

function Point(x, y) {
    this.x = x;
    this.y = y;
}

NinePatch.start = function (imageUrl) {
/*
    var container = document.getElementById("imageContainer");
    container.innerHTML = "";
    var image = document.createElement("img");
    image.onload = function () {
        NinePatch.createPatches(image);
    };
    container.appendChild(image);
    image.src = imageUrl;
*/
    var image = getSourceImageContainer().firstChild;
    NinePatch.createPatches(image);
};

function handleImageLoad () {
    var image = getSourceImageContainer().firstChild;
    var path = document.getElementById("path");
    var html = "<strong>Path:</strong><br/>";
    html += image.src;
    html += "<br/><strong>Size: </strong>" + (image.width - 2) + " x " + (image.height - 2);
    path.innerHTML = html;
    NinePatch.createPatches(image);
};

NinePatch.createPatches = function (image) {
    var w = image.width;
    var h = image.height;
    
    var canvas = document.getElementById("canvas");
    var parsedImageContainer = document.getElementById("parsedImageContainer");
    parsedImageContainer.innerHTML = "";
    
    canvas.setAttribute("width", w);
    canvas.setAttribute("height", h);
    var context = canvas.getContext("2d");
    context.clearRect(0, 0, w, h);