是否可以在客户端 PC 上使用客户端选择的图像而不将图像上传到服务器。
如果是,哪种网络编程语言可以做到这一点?
您可以使用 HTML5 Canvas,无需使用插件等。
加载图像,更改画布大小并绘制图像。也可以将结果提取为 dataUrl。
<!DOCTYPE HTML>
<html>
<head>
<style>
body { margin: 0px; padding: 0px; }
</style>
</head>
<body>
<canvas id="myCanvas" width="578" height="200"></canvas>
<script>
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
var imageObj = new Image();
imageObj.onload = function() {
// draw cropped image
var sourceX = 150;
var sourceY = 0;
var sourceWidth = 150;
var sourceHeight = 150;
var destWidth = sourceWidth;
var destHeight = sourceHeight;
var destX = canvas.width / 2 - destWidth / 2;
var destY = canvas.height / 2 - destHeight / 2;
context.drawImage(imageObj, sourceX, sourceY, sourceWidth, sourceHeight, destX, destY, destWidth, destHeight);
};
imageObj.src = 'http://www.html5canvastutorials.com/demos/assets/darth-vader.jpg';
</script>
</body>
</html>
所有功劳归于:
http://www.html5canvastutorials.com/tutorials/html5-canvas-image-crop/
这只能通过或自定义来完成Flash
,具体取决于目标浏览器。Silverlight
Plugin/ActiveX
这也可以使用 jQuery、MooTools、Prototype 和 script.aculo.us 等 javascript 库来完成:
http://www.bitrepository.com/image-cropping-with-jquery-mootools-prototype-scriptaculous.html
如果您正在通过 javascript 寻找图像裁剪器,请查看:https ://github.com/supnate/icropper 。它提供了用于裁剪但不是真正裁剪图像的用户界面。