Надежное программирование
Исключение может возникнуть при следующих условиях.
· Попытка указать точку за пределами точечного рисунка.
How to: Convert Images from One Format to Another
This example demonstrates loading an image and saving it in several different graphics formats.
Example
class Program { static void Main(string[] args) { // Load the image. System.Drawing.Image image1 = System.Drawing.Image.FromFile(@"C:\test.bmp"); // Save the image in JPEG format. image1.Save(@"C:\test.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); // Save the image in GIF format. image1.Save(@"C:\test.gif", System.Drawing.Imaging.ImageFormat.Gif); // Save the image in PNG format. image1.Save(@"C:\test.png", System.Drawing.Imaging.ImageFormat.Png); } } |
Compiling the Code
You can compile the example at a command prompt or paste the code into a console application by using the IDE. In the latter case, you must reference the System.Drawing.dll file.
Replace "c:\test.bmp", "c:\test.jpg", "c:\test.gif" and c:\test.png with the actual file name.
Преобразование изображений из одного формата в другой
В этом примере показана загрузка изображения и его сохранение в нескольких различных графических форматах.
Пример[28]
ß-----
Компиляция кода
Пример можно скомпилировать в командной строке либо вставить код в консольное приложение с помощью IDE. В последнем случае необходимо добавить ссылку на файл System.Drawing.dll.
Замените "c:\test.bmp", "c:\test.jpg", "c:\test.gif" and c:\test.png фактическим именем файла.
Customizing, Displaying, and Printing Windows Forms
This topic provides links to topics that show you how to perform tasks specific to Windows Forms, such as customizing the shape and color of a form, and displaying and printing forms.
How to: Change the Background Color of a Form
This example changes the background color of a Windows Form programmatically.
Example
private void Form1_Click(object sender, EventArgs e) { this.BackColor = System.Drawing.Color.DarkBlue; } |
Compiling the Code
This example requires:
· A form named Form1. Set its Click event handler to Form1_Click.
How to: Create a Shaped Form
The following example gives a form an elliptical shape.
Example
System.Drawing.Drawing2D.GraphicsPath shape = new System.Drawing.Drawing2D.GraphicsPath(); shape.AddEllipse(0, 0, this.Width, this.Height); this.Region = new System.Drawing.Region(shape); |
Compiling the Code
To use this code, copy it to the Form1_Load event handler.
The Region property of the Form class is an advanced member.
Дата добавления: 2022-05-27; просмотров: 148;