LEADTOOLS JavaScript 客户端图像处理

实现零足迹(zero footprint)应用程序的方法虽多,然而许多的应用只是简单的把所有的图片推给服务器端处理,图像处理性能和质量就大打折扣。有了LEADTOOLS JavaScript库,这些问题都可以引刃而解。LEADTOOLS JavaScript不仅可以快速执行其客户端图像处理事务,还大大降低了应用程序开发的工作量,只需要几行代码便可初始化查看器和图像处理引擎:

function InitializeComponents() {
// Setup the Viewer
_imageViewer = new Leadtools.Controls.ImageViewer(new Leadtools.Controls.ImageViewerCreateOptions("myLeadImageViewer", "myLeadImageViewerControlID"));
_imageViewer.set_imageUrl("Content/cannon.jpg");

// Set size mode and initialize image processing after image loaded
_imageViewer.add_imageChanged(function () {
_imageViewer.set_sizeMode(Leadtools.Controls.ImageViewerSizeMode.fitWidth);
InitImageProcessing();
});

_imageViewer.set_defaultInteractiveMode(new Leadtools.Controls.ImageViewerPanZoomInteractiveMode);
}

function InitImageProcessing() {
var myCanvas = _imageViewer.get_backCanvas();
var context = myCanvas.getContext("2d");

_imageProcessing = new Leadtools.ImageProcessing();

_imageProcessing.add_completed(function (sender, e) {
context.putImageData(e.get_imageData(), 0, 0);
_imageViewer.invalidate();
});
}

接下来,通过设置参数和调用运行便可执行图像处理算法。

function SetIPParams(filterName, ctx, canvas) {
var myCanvas = _imageViewer.get_backCanvas();
var ctx = myCanvas.getContext("2d");

_imageProcessing.set_jsFilePath("Scripts/Leadtools.ImageProcessing.Effects.js");
_imageProcessing.set_command(filterName);
_imageProcessing.set_imageData(ctx.getImageData(0, 0, myCanvas.width, myCanvas.height));
return _imageProcessing;
}

function SharpenFilter() {
var imageProcessing = SetIPParams("Sharpen");
imageProcessing.get_arguments()["sharpness"] = 750;
imageProcessing.get_arguments()["threshold"] = 0;

imageProcessing.run();
}

function GaussianFilter() {
var imageProcessing = SetIPParams("GaussianFilter");
imageProcessing.get_arguments()["radius"] = 10;

imageProcessing.run();
}

此时,我们已成功地将强大而快速的客户端图像处理程序添加的HTML5/ JavaScript应用程序中。下载并运行完整示例。

 

 

你可能感兴趣的:(图像处理,LEADTOOLS)