图片裁剪参见:

http://deepliquid.com/projects/Jcrop/demos.php?demo=thumbnail        一个js插件

http://www.mikesdotnetting.com/article/95/upload-and-crop-images-with-jquery-jcrop-and-asp-net  一个外国人写的例子,基于 asp.net webform 的。别人 在 2009 年 写的啊,我却在 2014年 才使用。

一共2个aspx 页面。

第一个页面是个人中心,用来编辑个人信息的:

部分代码如下:

<div class="row pad">
<div class="col-md-3">
</div>
<div class="col-md-1">
头像
</div>
<div class="col-md-7"> <iframe style="width: 100%; border: none;" height="" src="PersonalCenter_HeadImg.aspx" id="HeadImg_iframe"></iframe>
</div> </div>

第二个页面:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PersonalCenter_HeadImg.aspx.cs" Inherits="KT_Product_Show_V3.PersonalCenter_HeadImg" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Aspect Ratio with Preview Pane | Jcrop Demo</title>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
<script src="js/jquery.min.js"></script>
<script src="plug/tapmodo-Jcrop/js/jquery.Jcrop.js"></script>
<script type="text/javascript">
var Temp;
jQuery(function ($) {
// Create variables (in this scope) to hold the API and image size
var jcrop_api,
boundx,
boundy, // Grab some information about the preview pane
$preview = $('#preview-pane'),
$pcnt = $('#preview-pane .preview-container'),
$pimg = $('#preview-pane .preview-container img'), xsize = $pcnt.width(),
ysize = $pcnt.height(); console.log('init', [xsize, ysize]);
$('#target').Jcrop({
onChange: updatePreview,
onSelect: updatePreview,
aspectRatio: xsize / ysize
}, function () {
// Use the API to get the real image size
var bounds = this.getBounds();
boundx = bounds[];
boundy = bounds[];
// Store the API in the jcrop_api variable
jcrop_api = this;
Temp = this;
// Move the preview into the jcrop container for css positioning
$preview.appendTo(jcrop_api.ui.holder);
}); function updatePreview(c) {
if (parseInt(c.w) > ) {
var rx = xsize / c.w;
var ry = ysize / c.h; $pimg.css({
width: Math.round(rx * boundx) + 'px',
height: Math.round(ry * boundy) + 'px',
marginLeft: '-' + Math.round(rx * c.x) + 'px',
marginTop: '-' + Math.round(ry * c.y) + 'px'
});
}
}; }); </script>
<script>
window.onload = function () {
var input = document.getElementById("demo_input");
var result = document.getElementById("result");
var img_area = document.getElementById("img_area");
if (typeof (FileReader) === 'undefined') {
result.innerHTML = "抱歉,你的浏览器不支持 FileReader,请使用现代浏览器操作!";
input.setAttribute('disabled', 'disabled');
} else {
input.addEventListener('change', readFile, false);
}
}
function readFile() {
var file = this.files[];
//这里我们判断下类型如果不是图片就返回 去掉就可以上传任意文件
if (!/image\/\w+/.test(file.type)) {
alert("请确保文件为图像类型");
return false;
}
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function (e) {
$("#maxWidth").val(window.parent.$("#HeadImg_iframe")[].parentNode.clientWidth - );
$("#hid").val(this.result)
$("#form1").submit(); // $("#result").val(this.result);
// $("#target")[0].src = this.result;
// $("#target")[0].src = this.result; }
} </script>
<link href="plug//tapmodo-Jcrop/demos/demo_files/main.css" rel="stylesheet" />
<link href="plug//tapmodo-Jcrop/demos/demo_files/demos.css" rel="stylesheet" />
<link href="plug//tapmodo-Jcrop/css/jquery.Jcrop.css" rel="stylesheet" />
<style type="text/css">
.jcrop-holder #preview-pane {
display: block;
position: absolute;
z-index: ;
top: 10px;
right: -100px;
padding: 6px;
border: 1px rgba(,,,.) solid;
background-color: white;
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
border-radius: 6px;
-webkit-box-shadow: 1px 1px 5px 2px rgba(, , , 0.2);
-moz-box-shadow: 1px 1px 5px 2px rgba(, , , 0.2);
box-shadow: 1px 1px 5px 2px rgba(, , , 0.2);
} #preview-pane .preview-container {
width: 73px;
height: 73px;
overflow: hidden;
}
</style> </head>
<body>
<div class="btn-group">
<button class="btn btn-default" onclick="javascript: $('#demo_input').click()" type="button">选择图片</button>
</div>
<input type="file" style="display: none" value="" id="demo_input" /> <div id="img_area"></div>
<div class="">
<%--container--%>
<div class="">
<%--row--%>
<div class="">
<%--span12--%>
<div class="jc-demo-box" style="padding: 0px;"> <img src="" runat="server" id="target" alt="" /> <div id="preview-pane">
<div class="preview-container"> <img src="" runat="server" id="target002" class="jcrop-preview" alt="" />
</div>
</div> <div class="description">
</div> <div class="clearfix"></div> </div>
</div>
</div>
</div> <form id="form1" runat="server">
<div> <input type="hidden" name="hid" id="hid" />
<input type="hidden" name="maxWidth" value="" id="maxWidth" />
</div> <%--<asp:Button ID="Button1" runat="server" Text="Button"></asp:Button>--%>
</form>
</body>
<script>
// var r = window.parent.$("#HeadImg_iframe")[0].parentNode.clientWidth;
if (window.parent.$("#HeadImg_iframe")[] && $("body")[].clientHeight>) {
window.parent.$("#HeadImg_iframe")[].height = $("body")[].clientHeight;
} // Temp.setSelect(0,0,200,200);
</script>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using KT_Product_Show_V3.Controllers; namespace KT_Product_Show_V3
{
public partial class PersonalCenter_HeadImg : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Form["hid"] != null)
{
int maxWidth = int.Parse(Request.Form["maxWidth"].ToString());
string Img_url = ImageTool.DescripttionDecodeCutMaxWidth(Request.Form["hid"].ToString(), maxWidth);
target.Attributes.Add("src", Img_url);
target002.Attributes.Add("src", Img_url);
// Response.Write(Request.Form["hid"].ToString());
}
}
}
}

本来是打算实现 客户端 裁剪 直接 生成 base64 图片,然后直接上传,不需要消耗服务器性能。可惜 没有实现。这也是一个负载均衡的问题,也可以考虑一键切换功能。

bootstrap-wysiwyg 结合 base64 解码 .net bbs 图片操作类 (二) 图片裁剪的更多相关文章

  1. bootstrap-wysiwyg 结合 base64 解码 .net bbs 图片操作类

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Dr ...

  2. C#——图片操作类简单封装

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Dr ...

  3. Android应用程序开发之图片操作(二)——工程图片资源的加载及OOM的处理

    (一)工程图片资源的加载方法 在Android应用程序开发之图片操作(一)中,详细说明了如何操作各种资源图片,只是有的没有附上示例代码,在此,我将针对项目工程中的图片资源的显示加载进行说明.官方说明, ...

  4. php 图片操作类,支持生成缩略图,添加水印,上传缩略图

    <?php class Image {     //类开始     public $originimage = ""; //源图片文件地址     public $image ...

  5. bootstrap-wysiwyg 结合 base64 解码 .net bbs 图片操作类 (三) 图片裁剪

    官方的例子 是 长方形的. 我这里 用于 正方形的头像 所以  做如下  修改 #preview-pane .preview-container { width: 73px; height: 73px ...

  6. IO流操作-图片操作(二)

    一:Stream和Byte的含义 Stream:流,一般指文件流,内存流,可读的流和可写的流等,是一种数据转换的格式,流在计算机里可以表示为流输入或输出的一个连续的字节序列,它在使用完后,需要把资源释 ...

  7. C#获取CPU与网卡硬盘序列号及Base64和DES加密解密操作类

    public class RegisterHelp { /// <summary> /// CPU /// </summary> /// <returns>< ...

  8. java常用开发工具类之 图片水印,文字水印,缩放,补白工具类

    import java.awt.AlphaComposite; import java.awt.Color; import java.awt.Font; import java.awt.Graphic ...

  9. 微信小程序之图片base64解码

    不知道大家在做微信小程序的时候遇到base64解码的问题,我之前在做微信小程序的时候遇到base64解析图片一直有问题,所以在这里把遇到的问题和解决方案在这里记录一下: 在平时的项目中我们是直接用ba ...

随机推荐

  1. Twitter 新一代流处理工具——Heron 该纸币Storm Limitations

    Twitter 新一代流处理工具--Heron 该纸币Storm Limitations (空格分隔): Streaming-Processing Storm Problems scalability ...

  2. EJB(一)认识ejb

    什么是ejb? 相同仍旧在这个系列博客之处,谈谈对ejb的认识和理解.         sun微公司对于ejb的定义大体是这种,ejb是一套用于开发和部署分布式组件的的架构.採用ejb的架构应用能够是 ...

  3. C#基础之二

    C#基础之二 1.  静态字段.静态成员:由该类的所有实例共享,其变化,实例是对所有可见. 2.  声明为static有:场.方法.属性.构造函数.运营商.事件. 3.  不同的常量静态量:位置,在编 ...

  4. Team Foundation Server 2015使用教程--团队项目删除

  5. [Python]sqlite3二进制文件存储问题(BLOB)(You must not use 8-bit bytestrings unless you use a text_factory...)

    事情是这种: 博主尝试用Python的sqlite3数据库存放加密后的usernamepassword信息,表是这种 CREATE TABLE IF NOT EXISTS user ( userID ...

  6. uva 10817 - Headmaster's Headache ( 状态压缩dp)

    本文出自   http://blog.csdn.net/shuangde800 题目链接: 点击打开链接 题目大意 某校有n个教师和m个求职者,已知每人的工资和能教的课程集合,要求支付最少的工资使得每 ...

  7. springmvc 接收对象 滴灌摘要

    js 对象 该阵列看起来像 我明白http://blog.csdn.net/baicp3/article/details/12752255本文 我们指示样品棒 data3一个js对象.遗嘱java当代 ...

  8. 跑openstack命令错误【You must provide a username via either -...】

    openstack设置环境,openstack该服务已经启动.当运行openstack当一个命令,如nova service list例如,下面的错误信息 You must provide a use ...

  9. Android: ADT 23.0.2

    http://pan.baidu.com/s/1gdnBUUJ 版权声明:本文博主原创文章.博客,未经同意不得转载.

  10. Windows下一个SlikSVN使用

    我相信所有的应SVN不熟悉.使用过.可是并非人人都自己配置过SVNserver.以下就是我配置SVNserver的步骤.以及在配置过程中碰见的一些问题,在此记录,希望对你有所帮助. 安装 双击执行&q ...