bootstrap-wysiwyg 结合 base64 解码 .net bbs 图片操作类 (二) 图片裁剪
图片裁剪参见:
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 图片操作类 (二) 图片裁剪的更多相关文章
- bootstrap-wysiwyg 结合 base64 解码 .net bbs 图片操作类
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Dr ...
- C#——图片操作类简单封装
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Dr ...
- Android应用程序开发之图片操作(二)——工程图片资源的加载及OOM的处理
(一)工程图片资源的加载方法 在Android应用程序开发之图片操作(一)中,详细说明了如何操作各种资源图片,只是有的没有附上示例代码,在此,我将针对项目工程中的图片资源的显示加载进行说明.官方说明, ...
- php 图片操作类,支持生成缩略图,添加水印,上传缩略图
<?php class Image { //类开始 public $originimage = ""; //源图片文件地址 public $image ...
- bootstrap-wysiwyg 结合 base64 解码 .net bbs 图片操作类 (三) 图片裁剪
官方的例子 是 长方形的. 我这里 用于 正方形的头像 所以 做如下 修改 #preview-pane .preview-container { width: 73px; height: 73px ...
- IO流操作-图片操作(二)
一:Stream和Byte的含义 Stream:流,一般指文件流,内存流,可读的流和可写的流等,是一种数据转换的格式,流在计算机里可以表示为流输入或输出的一个连续的字节序列,它在使用完后,需要把资源释 ...
- C#获取CPU与网卡硬盘序列号及Base64和DES加密解密操作类
public class RegisterHelp { /// <summary> /// CPU /// </summary> /// <returns>< ...
- java常用开发工具类之 图片水印,文字水印,缩放,补白工具类
import java.awt.AlphaComposite; import java.awt.Color; import java.awt.Font; import java.awt.Graphic ...
- 微信小程序之图片base64解码
不知道大家在做微信小程序的时候遇到base64解码的问题,我之前在做微信小程序的时候遇到base64解析图片一直有问题,所以在这里把遇到的问题和解决方案在这里记录一下: 在平时的项目中我们是直接用ba ...
随机推荐
- 对比Windows 8模拟器(Simulator)和Windows Phone仿真器(Emulator)
原文:对比Windows 8模拟器(Simulator)和Windows Phone仿真器(Emulator) 从事移动应用开发,经常会用到模拟器(Simulator)和仿真器(Emulator),本 ...
- 基于nodejs 的微信 JS-SDK 简单应用
2015 是 Hybrid App 崛起之年 ,Web App 和 Native App 各有其强大之处,也有着致命的缺点,人们一边追求native流畅的用户体验,一边同时期望产品能够快速的迭代更新, ...
- ProducerConsumerDemo
package algorithm; public class ProducerConsumer { public static void main(String[] args) { SyncStac ...
- 【Leetcode】Partition List (Swap)
Given a linked list and a value x, partition it such that all nodes less than x come before nodes gr ...
- 数据结构(C达到)------- 双链表
双链表中的每个节点包含两个指针域,指针域包含其后继节点的内存地址,还有一个指针所存储的存储器地址其领域前驱节点. 双向链表结点的类型描写叙述: //双向链表的类型描写叙述 typedef int El ...
- 定向爬虫之爬一爬各个学校新闻的认识(【1】对Url的认识)
昨天早上,我习惯性的打开博客园,看一看别人的写的博客.突然想起,自己好像没有写过什么博客,所以就心血来潮,把我现在做得事情写出来, 这也是对我目前的学习的一种总结.望大神指点.... 对于一间学校的新 ...
- COCOFrame
COCOFrame它是一个轻量级的开发框架,综合Android APP开发过程中经常使用的工具,方法,特效.当中F类採用的AndroidQuery实现,做了进一步的封装及部分优化. 1. Jar包大小 ...
- Cocos2d-x源代码解析(1)——地图模块(3)
接上一章<Cocos2d-x源代码解析(1)--地图模块(2)> 通过前面两章的分析,我们能够知道cocos将tmx的信息结构化到 CCTMXMapInfo.CCTMXTilesetInf ...
- Sqlite学习笔记(四)&&SQLite-WAL原理(转)
Sqlite学习笔记(三)&&WAL性能测试中列出了几种典型场景下WAL的性能数据,了解到WAL确实有性能优势,这篇文章将会详细分析WAL的原理,做到知其然,更要知其所以然. WAL是 ...
- .NET单元测试艺术(1) - 单元测试的基本知识
List 1.1 一个要测试的SimpleParser类 using System; namespace AOUT.CH1.Examples { public class SimpleParser { ...