客户端读取图片文件

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-

transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" > 
<head>      
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />      
<title>Ajax文件上传</title>      
<style type="text/css"> 
#preview{width:100px;height:100px;border:1px solid #000;overflow:hidden;} 
#imghead {filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=image);} 
</style> 
<script type="text/javascript"> 
function previewImage(file) 

  var MAXWIDTH  = 100; 
  var MAXHEIGHT = 100; 
  var div = document.getElementById(‘preview‘); 
  if (file.files && file.files[0]) 
  { 
    div.innerHTML = ‘<img id=imghead>‘; 
    var img = document.getElementById(‘imghead‘); 
    img.onload = function(){ 
      var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, img.offsetWidth, img.offsetHeight); 
      img.width = rect.width; 
      img.height = rect.height; 
      img.style.marginLeft = rect.left+‘px‘; 
      img.style.marginTop = rect.top+‘px‘; 
    } 
    var reader = new FileReader(); 
    reader.onload = function(evt){img.src = evt.target.result;} 
    reader.readAsDataURL(file.files[0]); 
  } 
  else 
  { 
    var sFilter=‘filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src="‘; 
    file.select(); 
    var src = document.selection.createRange().text; 
    div.innerHTML = ‘<img id=imghead>‘; 
    var img = document.getElementById(‘imghead‘); 
    img.filters.item(‘DXImageTransform.Microsoft.AlphaImageLoader‘).src = src; 
    var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, img.offsetWidth, img.offsetHeight); 
    status =(‘rect:‘+rect.top+‘,‘+rect.left+‘,‘+rect.width+‘,‘+rect.height); 
    div.innerHTML = "<div id=divhead style=‘width:"+rect.width+"px;height:"+rect.height+"px;margin-

top:"+rect.top+"px;margin-left:"+rect.left+"px;"+sFilter+src+"\"‘></div>"; 
  } 

function clacImgZoomParam( maxWidth, maxHeight, width, height ){ 
    var param = {top:0, left:0, width:width, height:height}; 
    if( width>maxWidth || height>maxHeight ) 
    { 
        rateWidth = width / maxWidth; 
        rateHeight = height / maxHeight; 
         
        if( rateWidth > rateHeight ) 
        { 
            param.width =  maxWidth; 
            param.height = Math.round(height / rateWidth); 
        }else 
        { 
            param.width = Math.round(width / rateHeight); 
            param.height = maxHeight; 
        } 
    } 
     
    param.left = Math.round((maxWidth - param.width) / 2); 
    param.top = Math.round((maxHeight - param.height) / 2); 
    return param; 

</script>      
</head>      
<body> 
<div id="preview"> 
    <img id="imghead" width=100 height=100 border=0 src=‘../images/head01_big.jpg‘> 
</div> 
    <br/>      
    <input type="file" onchange="previewImage(this)" />      
</body>      
</html>

时间: 2024-08-09 06:21:45

客户端读取图片文件的相关文章

c#读取图片文件

1 /// <summary> 2 /// 读取图片文件 3 /// </summary> 4 /// <param name="path">图片文件路径</param> 5 /// <returns>图片文件</returns> 6 private Bitmap ReadImageFile(String path) 7 { 8 Bitmap bitmap=null; 9 try 10 { 11 FileStrea

在angularjs客户端压缩图片文件然后上传

主要是利用html5的canvas来进行图片的压缩,然后转化为dataURL,再有dataURL转化为Blob文件,Blob对象可以直接赋值给Formdata. app.service('Util', function($q) { var dataURItoBlob = function(dataURI) { // convert base64/URLEncoded data component to raw binary data held in a string var byteString

java读取图片文件 写入图片

Silverlight项目笔记8:层次布局、客户端读取shp、ExecuteCountAsync、柱状图、url传参

1.层次布局 由于地图窗口和菜单栏都在一个父容器内,在浏览器缩小到一定程度点击地图弹出infoWindow时,会出现菜单栏遮挡infoWindow中间部分的现象,于是通过设置Canvas.ZIndex来设置显示层次顺序解决这种冲突. 2.客户端读取Shp文件 有一个应用场景时用户自定义一个范围进行数据统计,包括用户上传已有Shp数据来确定统计区域,如何读取shp文件呢?答案是用了开源的ShapeFileReader类,转化得到graphic,客户端再处理即可.下载地址 http://esrisl

ifstream读取图片,Qt载入显示

应用场景: 需要显示图片的同时也需要图片的二进制数据.例如需要将图片作为二进制数据转化为string发送,而同时需要显示图片. 主要思路: 将图片文件用二进制格式读入,然后将二进制数据加载到 QImage 中,达到显示效果.让后根据需要,将读取到的二进制数据自行做处理. 主要代码: //begin std::ifstream fileInput("F:\\VSprojects\\DChat\\1.jpg", std::ios_base::binary); //获取文件大小 fileIn

读取保存文件、图片在数据库中的上传读取

一.输入输出流 1.概念: 输入输出流主要用于保存.读取文件,其内容保存在内存中. 2.使用方法: using System.IO; //System.IO 命名空间包含允许读写文件和数据流的类型以及提供基本文件和目录支持的类型. 3.代码段实现读取和保存功能: 读取文字: OpenFileDialog op = new OpenFileDialog(); op.ShowDialog();//打开文件对话框 //将选择的东西读取到文档里 StreamReader sd = new StreamR

【文件】读取一个文件夹下所有的jpg图片

今天做视频处理的时候,发现给的视频是用jpg图片的形式给出的,名字的命名规律性不是很强.就想找一种通用的遍历文件夹下图片的方法. 开始在网上找到了下面这份代码,发现只能读取所有的文件夹,文件都被跳过了 后来发现,原来是判断的if语句出了问题.dwFileAttributes有很多种属性如: FILE_ATTRIBUTE_ARCHIVE FILE_ATTRIBUTE_COMPRESSED FILE_ATTRIBUTE_DIRECTORY FILE_ATTRIBUTE_HIDDEN FILE_ATT

[转] 从数据库中读取图片并导入Excel文件,C#方式

原文地址, 作者 Lvyou1980 直接源码吧. using System; using System.IO; using System.Data; using System.Drawing; using System.Drawing.Imaging; using System.Windows.Forms; using Excel; private void EduceExcel() { string picPath=Directory.GetCurrentDirectory()+'\\Exc

客户端Android和Webservice之间的图片文件传输解决方法

最近在写webservice接口 给客户端提供数据和接收客户端发来的数据.当数据类型为图片类型的文件时候,先把文件转为流,然后用Base64编码成字节流的字符串,传输的还是字符串. 客户端代码: public static void main(String[] args) throws IOException { File file=new File("d:/272.jpg"); FileInputStream fis = new FileInputStream(file); Byte