怎么在内存中建立一张图片,然后显示在页面上(不保存在文件里)?急,马上结帖,谢谢

kingmd 2003-11-04 10:12:57
怎么在内存中建立一张图片,然后显示在页面上(不保存在文件里)?急,马上结帖,谢谢
...全文
61 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
ddangerous169 2003-11-04
  • 打赏
  • 举报
回复
creat one image object,then draw one pic ,then
Image.Save(Response.OutputStream,ImageFormat.Gif)
rgbcn 2003-11-04
  • 打赏
  • 举报
回复
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<script runat="server">

void Page_Load(Object s, EventArgs e) {

double photoWidth,photoHeight;
double percentageDifference = 0;
bool heHasAccess = false;
System.Drawing.Image inputImage;

//get information being sent
heHasAccess = true;

//get file name
string pictureFileName = Request.QueryString["f"];
if(pictureFileName == null || pictureFileName == "") {
heHasAccess = false;
}

//get width
try {
if (Request.QueryString["w"] == null) {
photoWidth = 0;
} else {
photoWidth = Int32.Parse(Request.QueryString["w"]);
}
}
catch {
photoWidth = 0;
}

//if anything went wrong, show error picture
if(!heHasAccess) {
inputImage = System.Drawing.Image.FromFile(Server.MapPath("images/pictureNoAccess.jpg"));
} else {
inputImage = System.Drawing.Image.FromFile(Server.MapPath("images/" + pictureFileName));
}

//if no width was given, assume the default now
if(photoWidth==0) {
if(!heHasAccess) {
photoWidth = 100;
} else {
photoWidth = inputImage.Width;
}
}

//define size for new image
percentageDifference = inputImage.Width / photoWidth;
photoHeight = inputImage.Height / percentageDifference;

//output new image with different size
Bitmap outputBitMap = new Bitmap(inputImage,Convert.ToInt32(photoWidth),Convert.ToInt32(photoHeight));
Response.ContentType = "image/jpeg";
outputBitMap.Save(Response.OutputStream, ImageFormat.Jpeg);

}
</script>
elfzzf 2003-11-04
  • 打赏
  • 举报
回复
发地址到我的邮箱 elf_1@163.net 留你的MAIL 我给你一个源项目
ameng_2002 2003-11-04
  • 打赏
  • 举报
回复
Image.Save(Response.OutputStream,ImageFormat.Gif)
pp4u 2003-11-04
  • 打赏
  • 举报
回复
从数据库中读出图片的字段,然后
<img src="<%#container.dataitem("img_url")%>">

acewang 2003-11-04
  • 打赏
  • 举报
回复
http://xml.sz.luohuedu.net/xml/ShowDetail.asp?id=221BC601-1A1B-4E1F-883D-04B043659703
qiuji 2003-11-04
  • 打赏
  • 举报
回复
给你一个例子,你可以参考一下。

在.aspx.cs文件中:

开始先using:
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;

在Page_Load事件中添加:
//定义图像的宽度、高度
int width=200;
int height=200;

Bitmap b=new Bitmap(width,height);
Graphics g=Graphics.FromImage(b);
g.Clear(Color.Yellow);

g.SmoothingMode=SmoothingMode.AntiAlias;
g.TextRenderingHint=TextRenderingHint.AntiAlias;

Pen p=new Pen(Color.Red);
g.DrawLine(p,20,100,180,180);

g.DrawString("显示的数据",new Font("arial",18,FontStyle.Bold),Brushes.DarkBlue,new PointF(10,50));

//设置输出图像格式
Response.ContentType="image/Gif";
b.Save(Response.OutputStream,ImageFormat.Gif);

//释放资源
b.Dispose();
g.Dispose();
wsqsoft 2003-11-04
  • 打赏
  • 举报
回复
Bitmap newBitmap = null;
Graphics g = null ;

String iNum;

double dResult;
Random ro = new Random();
dResult=ro.NextDouble()*100000;
iNum=dResult.ToString().Substring(0,4);

 
try
{
Font fontCounter = new Font("Arial", 9);
 
// calculate size of the string.
newBitmap = new Bitmap(1,1,PixelFormat.Format32bppArgb);
g = Graphics.FromImage(newBitmap);
SizeF stringSize = g.MeasureString(iNum, fontCounter);
int nWidth = (int)stringSize.Width;
int nHeight = (int)stringSize.Height;
g.Dispose();
newBitmap.Dispose();
 
newBitmap = new Bitmap(nWidth,nHeight,PixelFormat.Format32bppArgb);
g = Graphics.FromImage(newBitmap);
g.FillRectangle(new SolidBrush(Color.White),
new Rectangle(0,0,nWidth,nHeight));
 
g.DrawString(iNum, fontCounter,
new SolidBrush(Color.Black), 0, 0);
 
//newBitmap.Save("c:\\test.png", ImageFormat.PNG);

MemoryStream tempStream = new MemoryStream();
newBitmap.Save(tempStream,ImageFormat.Jpeg);
 

Response.ClearContent();
Response.ContentType = "image/Jpeg";
Response.BinaryWrite(tempStream.ToArray());
Response.End();
}
catch (Exception ei)
{
Console.WriteLine(ei.ToString());
}
finally
{
if (null != g) g.Dispose();
if (null != newBitmap) newBitmap.Dispose();
}
starry11 2003-11-04
  • 打赏
  • 举报
回复
mark

62,073

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧