Csharp/CSharp Tutorial/2D/Image — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 12:18, 26 мая 2010

DrawImage with Graphics

using System;
using System.Collections.Generic;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form {
    protected override void OnPaint(PaintEventArgs e) {
    Graphics g = e.Graphics;
    Bitmap bmp = new Bitmap("a.jpg");
    g.FillRectangle(Brushes.White, this.ClientRectangle);
    Rectangle sr = new Rectangle(80, 60, 400, 400);
    Rectangle dr = new Rectangle(0, 0, 200, 200);
    g.DrawImage(bmp, dr, sr, GraphicsUnit.Pixel);
    }
    public static void Main() {
        Application.Run(new Form1());
    }
}

Image.FromFile: load image from file

using System;
using System.Drawing;
using System.Windows.Forms;
   
class ImageFromFile: Form
{
     public static void Main()
     {
          Application.Run(new ImageFromFile());
     }
     public ImageFromFile()
     {
          Text = "Image From File";
          ResizeRedraw = true; 
     }
     protected override void OnPaint(PaintEventArgs pea)
     {
          DoPage(pea.Graphics, ForeColor,ClientSize.Width, ClientSize.Height);
     }     
     protected void DoPage(Graphics grfx, Color clr, int cx, int cy)
     {
          Image image = Image.FromFile("Color.jpg");
   
          grfx.DrawImage(image, 0, 0);
     }
}

Load Picture from Internet

using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
using System.Net;
using System.IO;
public class Form1 : System.Windows.Forms.Form {
    [STAThread]
    static void Main() {
        Application.Run(new Form1());
    }
    protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) {
        WebRequest wReq = WebRequest.Create("http://www.yoursite.ru/4.jpg");  // using System.Net;
        WebResponse wRes = wReq.GetResponse();
        Stream strm = wRes.GetResponseStream();
        Image im = Image.FromStream(strm);
        e.Graphics.DrawImage(im, 0, 50);
        strm.Close();
    }
}