using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Reflection;
using System.Resources;
using System.Text;
using System.Windows.Forms;
namespace ImageEx {
public partial class ImageForm : Form {
private Bitmap image; //イメージ
private ImageAttributes imageAttr;//イメージ属性
//コンストラクタ
public ImageForm() {
InitializeComponent();
//イメージの読み込み
try {
image=LoadImage("ImageEx.sorami.gif");
} catch (Exception exc) {
MessageBox.Show(exc.ToString(),"エラー");
}
//イメージ属性の生成
imageAttr=new ImageAttributes();
imageAttr.SetColorKey(
Color.FromArgb(255,0,255),
Color.FromArgb(255,0,255));
}
//イメージの読み込み
private Bitmap LoadImage(String name) {
return new Bitmap(Assembly.GetExecutingAssembly().
GetManifestResourceStream(name));
}
//イメージの描画
private void DrawImage(Graphics g,Bitmap image,int x,int y) {
g.DrawImage(image,
new Rectangle(x,y,image.Size.Width,image.Size.Height),
0,0,image.Size.Width,image.Size.Height,
GraphicsUnit.Pixel,imageAttr);
}
//サイズ指定でイメージ描画
private void DrawImage(Graphics g,Bitmap image,int x,int y,int w,int h) {
g.DrawImage(image,
new Rectangle(x,y,w,h),
0,0,image.Size.Width,image.Size.Height,
GraphicsUnit.Pixel,imageAttr);
}
//描画
protected override void OnPaint(PaintEventArgs pea) {
Graphics g=pea.Graphics;
if (image!=null) {
//イメージの描画
g.DrawImage(image,0,0);
//透過色指定してイメージ描画
DrawImage(g,image,0,120);
//倍サイズでイメージ描画
DrawImage(g,image,0,240,image.Size.Width*2,image.Size.Height*2);
}
}
}
}
|