回覆列表
  • 1 # 錢布斯

    你可以根據實際要求,修改下:

    //例項化 Bitmap

    Bitmap image = new Bitmap(300, 300);//圖片尺寸

    //從 Bitmap 例項建立Graphics例項

    Graphics graphics = Graphics.FromImage(image);

    //座標原點轉換到圖片左下角(GDI+預設原點在左上角)

    graphics.TranslateTransform(0, 298);

    //以白色填充圖片

    graphics.Clear(Color.White);

    //畫座標軸

    Pen pen=new Pen(Color.Black);

    graphics.DrawLine(pen, new Point(0, 0), new Point(300, 0));

    graphics.DrawLine(pen, new Point(0, 0), new Point(0, -300));

    //畫箭頭

    graphics.DrawLine(pen, new Point(300, 0), new Point(295, -5));

    graphics.DrawLine(pen, new Point(0, -300), new Point(5, -295));

    //刻度

    for (int i = 20; i < 300; i = i + 20)

    {

    //x軸

    graphics.DrawLine(pen, new Point(i, 0), new Point(i, -5));

    //y軸

    graphics.DrawLine(pen, new Point(0, i*-1), new Point(5, i*-1));

    }

    //畫矩形

    //假設矩形一個角的座標為80,100

    graphics.FillRectangle(Brushes.Blue,0,-100,80,100);

    //釋放Graphics物件

    graphics.Dispose();

    //圖形輸出到網頁

    Response.Clear();

    //設定Response的MIME

    Response.ContentType = "image/pjpeg";

    //將圖片儲存到Response的輸出流中

    image.Save(Response.OutputStream, ImageFormat.Jpeg);

    //寫入到Response輸出流中

    image.Dispose();

    Response.End();

  • 中秋節和大豐收的關聯?
  • 茶馬古道梅山遺風在哪裡?