| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1732 人关注过本帖, 1 人收藏
标题:动态生成image问题(紧急)
只看楼主 加入收藏
雪雨星风
Rank: 1
来 自:北京
等 级:新手上路
威 望:1
帖 子:566
专家分:0
注 册:2007-10-11
收藏
得分:0 
~image/123.jpg
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: ~image/123.jpg

源错误:


行 46:         g.DrawLine(new Pen(Color.GreenYellow), 20, 90, 380, 90);
行 47:         g.DrawRectangle(new Pen(Color.CornflowerBlue), 20, 20, 360, 560);
行 48:         System.Drawing.Image newimage = System.Drawing.Image.FromFile("~image/123.jpg");
行 49:         g.DrawImage(newimage, 100, 100, 40, 70);      
行 50:         Response.ContentType = "image/Jpeg";
 

源文件: e:\练习\baoming\Default.aspx.cs    行: 48

C#发烧友QQ群1:5953354   QQ群2:68096127  QQ群3:30217249  QQ群4:37023079   为了更好方便大家交流学习,请不要重复加群
2008-08-05 13:11
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 
System.Drawing.Image image = System.Drawing.Image.FromFile(imagePath);
Bitmap bitmap = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppArgb);
Graphics graphics = Graphics.FromImage(bitmap);
                //在指定位置并且按指定大小绘制 原图片 对象
graphics.DrawImage(image, new Rectangle(0, 0, image.Width, image.Height));  
.......
.......

注意:用Image时,一定要记得在用完以后关闭它,要不然你的内存会被一点一点吃掉.还有Bitmap也一样

飘过~~
2008-08-05 16:53
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 
System.Drawing.Image newimage = System.Drawing.Image.FromFile(Server.MapPath("~image/123.jpg"));

飘过~~
2008-08-05 16:53
cyyu_ryh
Rank: 8Rank: 8
等 级:贵宾
威 望:45
帖 子:1899
专家分:176
注 册:2006-10-21
收藏
得分:0 
我靠
题目看錯了
原来是向图片写字

有事无事都密我. MSN: cyyu_ryh@hotmail.co.jp E-mail: cyyu_ryh@
2008-08-05 17:16
雪雨星风
Rank: 1
来 自:北京
等 级:新手上路
威 望:1
帖 子:566
专家分:0
注 册:2007-10-11
收藏
得分:0 
谢谢各位了

C#发烧友QQ群1:5953354   QQ群2:68096127  QQ群3:30217249  QQ群4:37023079   为了更好方便大家交流学习,请不要重复加群
2008-08-06 09:51
雪雨星风
Rank: 1
来 自:北京
等 级:新手上路
威 望:1
帖 子:566
专家分:0
注 册:2007-10-11
收藏
得分:0 
[bo][un]bygg[/un] 在 2008-8-5 16:53 的发言:[/bo]

System.Drawing.Image image = System.Drawing.Image.FromFile(imagePath);
Bitmap bitmap = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppArgb);
Graphics graphics = Graphics.FromImage(bitm ...

sing System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.Drawing.Imaging;
using
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            gethua();            
        }
    }
    protected void gethua()
    {
        Random random = new Random();
        Bitmap bt = new Bitmap(351, 402, PixelFormat.Format24bppRgb);
        Graphics g = Graphics.FromImage(bt);
        Font fn1 = new Font("Tahoma", 10, FontStyle.Bold);         
        Font fn = new Font("Tahoma", 9, FontStyle.Bold);     
        g.Clear(Color.Honeydew);
        g.DrawString("中国电子学会电子设计初级工程师认证考试名", fn1, Brushes.Black, new PointF(20, 20));
        g.DrawString("准 考 证", fn1, Brushes.Black, new PointF(140, 50));
        g.DrawString("准考证号", fn, Brushes.Black, new PointF(14, 85));
        g.DrawString("CIE09101080004", fn, Brushes.Black, new PointF(90, 85));
        g.DrawString("考生姓名", fn, Brushes.Black, new PointF(14, 115));
        g.DrawString("李晓杰", fn, Brushes.Black, new PointF(90, 115));
        g.DrawString("考生性别", fn, Brushes.Black, new PointF(14, 145));
        g.DrawString("男", fn, Brushes.Black, new PointF(90, 145));
        g.DrawString("身份证号", fn, Brushes.Black, new PointF(14, 175));
        g.DrawString("410381198408272032", fn, Brushes.Black, new PointF(90, 175));
        g.DrawString("考试时间", fn, Brushes.Black, new PointF(14, 205));
        g.DrawString("2007年11月30号", fn, Brushes.Black, new PointF(90, 205));
        g.DrawString("考试科目", fn, Brushes.Black, new PointF(14, 235));
        g.DrawString("电子设计", fn, Brushes.Black, new PointF(90, 235));
        g.DrawString("考点名称", fn, Brushes.Black, new PointF(14, 265));
        g.DrawString("电子设计工程师证书", fn, Brushes.Black, new PointF(90, 265));
        g.DrawString("考场编号", fn, Brushes.Black, new PointF(14, 295));
        g.DrawString("9101080004", fn, Brushes.Black, new PointF(90, 295));
        g.DrawString("机位编号", fn, Brushes.Black, new PointF(196, 295));
        g.DrawString("080004", fn, Brushes.Black, new PointF(275, 295));
        g.DrawString("交通指南(由各考点提供)", fn, Brushes.Black, new PointF(14, 325));
        g.DrawString("在北京站可直接换乘环线地铁,在东四十条下车。", fn, Brushes.Black, new PointF(30, 340));      
        for (int i = 0; i < 500; i++)
        {
            int x1 = random.Next(bt.Width-20);            
            int y1 = random.Next(bt.Height-20);                                 
            bt.SetPixel(x1, y1, Color.FromArgb(random.Next()));            
        }
        for (int i = 0; i < 50; i++)
        {
            int x1 = random.Next(bt.Width-20);            
            int y1 = random.Next(bt.Height-20);
            int x2 = random.Next(1,30);            
            int y2 = random.Next(1,20);
            int x3 = random.Next(15,45);            
            int y3 = random.Next(70,270);
            g.DrawArc(new Pen(Color.FromArgb(random.Next())), x1, y1, x2, y2, x3, y3);
        }
        g.DrawLine(new Pen(Color.Black), 10, 75, 341, 75);
        g.DrawLine(new Pen(Color.Black), 10, 105, 243, 105);
        g.DrawLine(new Pen(Color.Black), 10, 135, 243, 135);
        g.DrawLine(new Pen(Color.Black), 10, 165, 243, 165);
        g.DrawLine(new Pen(Color.Black), 10, 195, 341, 195);
        g.DrawLine(new Pen(Color.Black), 10, 225, 341, 225);
        g.DrawLine(new Pen(Color.Black), 10, 255, 341, 255);
        g.DrawLine(new Pen(Color.Black), 10, 285, 341, 285);
        g.DrawLine(new Pen(Color.Black), 10, 315, 341, 315);
        g.DrawLine(new Pen(Color.Black), 80, 75, 80, 314);
        g.DrawLine(new Pen(Color.Black), 185, 285, 185, 314);
        g.DrawLine(new Pen(Color.Black), 265, 285, 265, 314);
        g.DrawLine(new Pen(Color.Black), 243, 75, 243, 195);
        g.DrawRectangle(new Pen(Color.CornflowerBlue), 10, 10, 331, 382);
        System.Drawing.Image newimage = System.Drawing.Image.FromFile("E:/练习/baoming/image/123.jpg");
        g.DrawImage(newimage, 245, 77, 95, 117);
        Response.ContentType = "image/Jpeg";
        bt.Save(Response.OutputStream, ImageFormat.Jpeg);        
    }   
}
当我打开vs第一次运行时 F5  生成一张图片   但是   我不关闭VS修改其中的信息   再次F5  再次生成一张图片
但是我右键另存这张图片   预览这张另存的图片时会发现另存的是打开vs第一次运行时 F5  生成的图片
这是为什么    是因为image没关闭的原因吗    image如何关闭

C#发烧友QQ群1:5953354   QQ群2:68096127  QQ群3:30217249  QQ群4:37023079   为了更好方便大家交流学习,请不要重复加群
2008-08-06 13:09
快速回复:动态生成image问题(紧急)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.050984 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved