1

I have 2 divs

<div id="image-orig">
    <img src="image_example.jpg"/>
</div>

<div id="image-crop">
    <canvas id="preview" style="width:548px;height:387px"></canvas>
</div>

image_example.jpg can be image any size.

    function updatePreview(c) {
        if(parseInt(c.w) > 0) {
            var orig = $("#image-orig img")[0];
            var canvas = $("#image-crop canvas")[0];
            var context = canvas.getContext("2d");

            context.drawImage(orig,
                c.x*coeff,c.y*coeff,c.w*coeff,c.h*coeff,
                0,0,canvas.width,canvas.height
            );
        }
     }

    $(function(){
            $('#image-orig img').Jcrop({
                onSelect: updatePreview,
                onChange: updatePreview,
                aspectRatio : parseFloat($('#image-orig img').width()/$('#image-orig img').height())
            });
    });

coeff - it's coefficient if size image larger div preview.

That's problem: http://dbwap.ru/3725988.png

In second div (canvas). Quality image very low.

SOLUTION IS FOUND

            canvas.width = c.w*coeff;
            canvas.height = c.h*coeff;

            context.drawImage(orig,
                c.x*coeff,c.y*coeff,c.w*coeff,c.h*coeff,
                0,0,c.w*coeff,c.h*coeff
            );
            $(that.el).find("#ImageCode").attr('src', canvas.toDataURL());
            $(that.el).find("#ImageCode").show();

I'm just creating image tag and copying from canvas to image.

4

1 回答 1

1

如果您有权访问 .net,则可以使用 JCrop 修改新图像的保存方式:http: //mironabramson.com/blog/post/2009/04/Cropping-image-using-jQuery,-Jcrop-and- ASPNET.aspx

无需使用服务器端 (.net / php) 即可为您提供的解决方案:

首先,确保在使用 JCrop 时启用了 html5 画布图像平滑:

http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html

如果已经设置或没有效果,那么我认为您唯一可以通过每个浏览器调查图像选项的其他选项:

在 Mozilla 中启用平滑- 以本文为例(查找“mozImageSmoothingEnabled”):https ://developer.mozilla.org/en/Canvas_tutorial/Using_images#Controlling_image_scaling_behavior

在 IE 中应用过滤器:http : //code.flickr.com/blog/2008/11/12/on-ui-quality-the-little-things-client-side-image-resizing/

注意:可能有某种 Flash 解决方案可以工作,但将任何 Flash 解决方案与 JCrop 和 html5 画布结合起来可能太困难了。

于 2012-06-06T15:10:44.200 回答