导航:首页 > 文件处理 > asp上传图片压缩

asp上传图片压缩

发布时间:2022-01-31 14:26:23

A. asp网站上传图片自动压缩图片大小代码,把以下代码修改成能够压缩图片的代码。

要压缩图片大小的必须要有组件,就是服务器要支持这个组件才可以。
下面介绍一个:
ASPJPEG是一款功能相当强大的图象处理组件,用它可以轻松地做出图片的缩略图和为图片加上水印功能。

实际怎么样我没有用过这个组件不做评价,你可以网上找找。

B. 求asp.net 图片上传压缩图片大小代码 就是减小图片的分辨率存储图片到服务器

c#生成图片缩略图的类
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;

/// <summary>
/// 图片处理类
/// 1、生成缩略图片或按照比例改变图片的大小和画质
/// 2、将生成的缩略图放到指定的目录下
/// </summary>
public class ImageClass
{
public Image ResourceImage;
private int ImageWidth;
private int ImageHeight;

public string ErrMessage;

/// <summary>
/// 类的构造函数
/// </summary>
/// <param name="ImageFileName">图片文件的全路径名称</param>
public ImageClass(string ImageFileName)
{
ResourceImage=Image.FromFile(ImageFileName);
ErrMessage="";
}

public bool ThumbnailCallback()
{
return false;
}

/// <summary>
/// 生成缩略图重载方法1,返回缩略图的Image对象
/// </summary>
/// <param name="Width">缩略图的宽度</param>
/// <param name="Height">缩略图的高度</param>
/// <returns>缩略图的Image对象</returns>
public Image GetRecedImage(int Width,int Height)
{
try
{
Image RecedImage;

Image.GetThumbnailImageAbort callb=new Image.GetThumbnailImageAbort(ThumbnailCallback);

RecedImage=ResourceImage.GetThumbnailImage(Width,Height,callb,IntPtr.Zero);

return RecedImage;
}
catch(Exception e)
{
ErrMessage=e.Message;
return null;
}
}

/// <summary>
/// 生成缩略图重载方法2,将缩略图文件保存到指定的路径
/// </summary>
/// <param name="Width">缩略图的宽度</param>
/// <param name="Height">缩略图的高度</param>
/// <param name="targetFilePath">缩略图保存的全文件名,(带路径),参数格式:D:Images ilename.jpg</param>
/// <returns>成功返回true,否则返回false</returns>
public bool GetRecedImage(int Width,int Height,string targetFilePath)
{
try
{
Image RecedImage;

Image.GetThumbnailImageAbort callb=new Image.GetThumbnailImageAbort(ThumbnailCallback);

RecedImage=ResourceImage.GetThumbnailImage(Width,Height,callb,IntPtr.Zero);
RecedImage.Save(@targetFilePath,ImageFormat.Jpeg);

RecedImage.Dispose();

return true;
}
catch(Exception e)
{
ErrMessage=e.Message;
return false;
}
}

/// <summary>
/// 生成缩略图重载方法3,返回缩略图的Image对象
/// </summary>
/// <param name="Percent">缩略图的宽度百分比 如:需要百分之80,就填0.8</param>
/// <returns>缩略图的Image对象</returns>
public Image GetRecedImage(double Percent)
{
try
{
Image RecedImage;

Image.GetThumbnailImageAbort callb=new Image.GetThumbnailImageAbort(ThumbnailCallback);

ImageWidth=Convert.ToInt32(ResourceImage.Width*Percent);
ImageHeight=Convert.ToInt32(ResourceImage.Width*Percent);

RecedImage=ResourceImage.GetThumbnailImage(ImageWidth,ImageHeight,callb,IntPtr.Zero);

return RecedImage;
}
catch(Exception e)
{
ErrMessage=e.Message;
return null;
}
}

/// <summary>
/// 生成缩略图重载方法4,返回缩略图的Image对象
/// </summary>
/// <param name="Percent">缩略图的宽度百分比 如:需要百分之80,就填0.8</param>
/// <param name="targetFilePath">缩略图保存的全文件名,(带路径),参数格式:D:Images ilename.jpg</param>
/// <returns>成功返回true,否则返回false</returns>
public bool GetRecedImage(double Percent,string targetFilePath)
{
try
{
Image RecedImage;

Image.GetThumbnailImageAbort callb=new Image.GetThumbnailImageAbort(ThumbnailCallback);

ImageWidth=Convert.ToInt32(ResourceImage.Width*Percent);
ImageHeight=Convert.ToInt32(ResourceImage.Width*Percent);

RecedImage=ResourceImage.GetThumbnailImage(ImageWidth,ImageHeight,callb,IntPtr.Zero);

RecedImage.Save(@targetFilePath,ImageFormat.Jpeg);

RecedImage.Dispose();

return true;
}
catch(Exception e)
{
ErrMessage=e.Message;
return false;
}
}

}
本篇文章来源于:开发学院 http://e.codepub.com 原文链接:http://e.codepub.com/2011/0118/28884.php

C. asp 实现图片上传的时候压缩他

按比例压缩图片:

SmallImgFilet = "SmallImg-"&smallname&".jpg" '小图片指定取名

If IsEmpty(SmallImgFile) then

'dim L as Single , H as Single

Set Jpeg = Server.CreateObject("Persits.Jpeg") '调用组件

Path = Server.MapPath("../") & "\" & BigImgFile '待缩小图片路径 放在根目录 你可以制定文件夹 在../后面
Jpeg.Open Path '打开图片
L = 120/80'缩略图高与宽比 你如果只限制宽度就不用下面else的高度比例判断 只按宽度的对应大图比例缩小就可以了

H= jpeg.OriginalWidth/jpeg.OriginalHeight

If H > L Then
jpeg.Width = 120
jpeg.Height = (jpeg.OriginalHeight*120)/jpeg.OriginalWidth
Else
jpeg.Height = 80
jpeg.Width = (jpeg.OriginalWidth*80)/jpeg.OriginalHeight
End If
'保存图片
Jpeg.Save Server.MapPath("../") & "\"&SmallImgFilet'&".jpg"
set Jpeg=nothing
end if

D. 我想问一下:ASP中,在上传图片的时候可不可以将图片压缩成相应大小,代码应该怎么写

用css吧比较好点

img,a img{
border:0;
margin:0;
padding:0;
max-width:590px;
width:expression(this.width>590?"590px":this.width);
max-height:590px;
height:expression(this.height>590?"590px":this.height);
}

E. asp中如何将上传的图片缩小尺寸

ASP自动压缩功能比较死板,压缩出来的图片也会变的大小不一。建议用ACDSEE之类的软件进行百分比批量压缩,这样出来的效果要比ASP压缩出来的高很多,而且图片质量也不会失真。

F. 使用“化境ASP无组件上传类”或是“风声无组件上传类”如何压缩图片

aspjpeg对,楼上说了,用aspjpeg。
Set Jpegppp = Server.CreateObject("Persits.Jpeg")
Jpegppp.Open FileName
Jpegppp.PreserveAspectRatio=true'等比缩放
Jpegppp.Interpolation=2
Jpegppp.Quality=100
Jpegppp.Width = 宽度
Jpegppp.crop 0,CInt((Jpegppp.Height-高度)/2),宽度,CInt((Jpegppp.Height-高度)/2)+高度
jpegppp.Sharpen 1, 120
Jpegppp.Save server.MapPath(strDir&""&file_numa&"2"&file_numab&fileEXT)
Jpegppp.close
set Jpegppp=nothing

G. asp:批量压缩主机上的图片大小

图片的压缩效率很低的,别费劲了,没用。

H. 如何让asp自动压缩图片大小

float k;
k=Img.Width/Img.Height;
if(Img.Width>Img.Height)
{
Img.Width=500;Img.Height=Convert.ToInt32(Convert.ToSingle(500)/k);
}
else
{
Img.Height=500;Img.Width=Convert.ToInt32(Convert.ToSingle(500)*k);
}

I. asp.net 将原图用代码自动压缩成规定大小后上传

上传时候判断原图片大小

然后根据大小判断

  System.Drawing.Image originalImage = System.Drawing.Image.FromStream(file.InputStream);
if (originalImage.Width > 800 || originalImage.Height > 800)

然后规定大小

这问题主要地方是如何获取图片的原大小,只要能获取原大小就能规定格式

J. asp图片上传压缩小,现在的上传方法上传的都是原图,太大了,访问速度太慢

给你一个过程你看下
<%
dim arr(3)
dim upload,file,formName,formPath,iCount,filename,fileExt,i
set upload=new upload_5xSoft ''建立上传对象

formPath="../upImgFile/" '图片存放的路径:proct目录下的uploadimages文件夹 ''在目录后加(/)

''列出所有上传了的文件
for each formName in upload.file
set file=upload.file(formName)
if file.filesize>0 then
if file.filesize>10000000 then
response.write "<font size=2>图片大小超小了限制[<a href=# onclick=history.go(-1)>重新上传</a>]</font>"
response.end
end if
fileExt=lcase(right(file.filename,4))
if fileExt<>".jpg" then
response.write "<font size=2>文件格式限制[<a href=# onclick=history.go(-1)>请重新上传</a>]</font>"
response.end
end if
end if

filename=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&file.FileName

if file.FileSize>0 then ''如果 FileSize > 0 说明有文件数据
file.SaveAs Server.mappath(formpath&filename) ''保存文件

' 图片位置
dim PhotoPath
PhotoPath = Server.MapPath(formpath&filename)
'缩小大图
call OKbigpic(PhotoPath)

'response.write file.FilePath&file.FileName&"("&file.FileSize&") => "&formPath&File.FileName&"上传成功<br>"
response.write "上传成功 <a href=# onclick=history.go(-1)>请返回</a>"

end if
set file=nothing
next
set upload=nothing
Response.Write "<script>parent.add.P_url.value='"&FileName&"'</script>"

sub OKbigpic(FileName)
Dim bigpic,bigpicPath,fss
Set bigpic = Server.CreateObject("Persits.Jpeg")
set fss=createobject("scripting.filesystemobject")
' 设置图片质量
bigpic.Interpolation=2
bigpic.Quality=90
' 图片位置
if fss.fileExists(FileName) then
bigpic.Open FileName

'下面是按比例缩放
n_MaxWidth=900
n_MaxHeight=1500

'按比例取得缩略图宽度和高度
Dim n_OriginalWidth, n_OriginalHeight '原图片宽度、高度
Dim n_BuildWidth, n_BuildHeight '缩略图宽度、高度
Dim div1, div2
Dim n1, n2
'修改Jpeg
n_OriginalWidth = bigpic.Width
n_OriginalHeight = bigpic.Height
div1 = n_OriginalWidth / n_OriginalHeight
div2 = n_OriginalHeight / n_OriginalWidth
n1 = 0
n2 = 0
If n_OriginalWidth > n_MaxWidth Then
n1 = n_OriginalWidth / n_MaxWidth
Else
n_BuildWidth = n_OriginalWidth
End If
If n_OriginalHeight > n_MaxHeight Then
n2 = n_OriginalHeight / n_MaxHeight
Else
n_BuildHeight = n_OriginalHeight
End If
If n1 <> 0 Or n2 <> 0 Then
If n1 > n2 Then
n_BuildWidth = n_MaxWidth
n_BuildHeight = n_MaxWidth * div2
Else
n_BuildWidth = n_MaxHeight * div1
n_BuildHeight = n_MaxHeight
End If
End If

'指定宽度和高度生成
bigpic.Width = n_BuildWidth
bigpic.Height = n_BuildHeight

' 保存文件
bigpic.Save (FileName)
' 注销对象
Set bigpic = Nothing

end if
end sub
%>

阅读全文

与asp上传图片压缩相关的资料

热点内容
数据挖掘中层次聚类算法实验 浏览:173
开发完app如何配置服务器 浏览:817
汽车压缩机工作但是压力不变 浏览:84
开发编译软件好吗 浏览:899
微信朋友圈发几兆的图片不会被压缩 浏览:289
单片机怎么让灯循环流水 浏览:400
联想服务器是什么芯片 浏览:710
山东西门子plc编程软件 浏览:399
贵阳买菜app叫什么 浏览:32
单片机直接驱动二极管优缺点 浏览:458
程序员和软件测试 浏览:420
程序员改造品牌 浏览:278
动态温度计编程 浏览:75
有什么app可以闹钟语音播报的 浏览:285
放量突破颈线选股源码 浏览:517
什么看文章的app可以赚钱 浏览:272
51单片机通讯错误 浏览:324
打开导航显示服务器忙是怎么回事 浏览:842
android应用框架设计 浏览:721
移动云服务器平台 浏览:782