- 題名: オフスクリーンの内容を同じオフスクリーンにコピーする
- 日時: 2006/08/07 21:16:51
- ID: 17043
- この記事の返信元:
- (なし)
- この記事への返信:
- [17044] Re[1]: オフスクリーンの内容を同じオフスクリーンにコピーする2006/08/07 22:16:28
- ツリーを表示
>buf.DrawImage(bufferImage, img1, img2 ,GraphicsUnit.Pixel);
本当ですね。Graphicsオブジェクトの作成元のイメージで描画しようとすると,
エラーがでるわけでもなく,何も描画されませんね。不思議です。
次のようなコードだと問題なく描画され,また速度もそこそこにでるようです。
namespace WindowsApplication1
{
public partial class Form1 : Form
{
private Image bufferImage = new Bitmap(1400, 1000);
public Form1()
{
InitializeComponent();
this.Load += new EventHandler(Form1_Load);
}
private void Form1_Load(object sender, EventArgs e)
{
BackGraund();
}
private void BackGraund()
{
Image UnitImage = new Bitmap(32, 32);
Graphics gUnit = Graphics.FromImage(UnitImage);
Brush brush1 = new SolidBrush(Color.Blue);
Brush brush2 = new SolidBrush(Color.White);
for (int y = 0; y < 8; y++)
{
for (int x = 0; x < 8; x++)
{
gUnit.FillRectangle(y % 2 == 0 ? x % 2 == 0 ? brush1 : brush2 : x % 2 == 0 ? brush2 : brush1, x * 4, y * 4, 4, 4);
}
}
brush2.Dispose();
brush1.Dispose();
gUnit.Dispose();
Graphics gBuf = Graphics.FromImage(bufferImage);
for (int y = 0; y < 31; y++)
{
for (int x = 0; x < 40; x++)
{
gBuf.DrawImage(UnitImage, x * 32, y * 32);
}
}
gBuf.Dispose();
UnitImage.Dispose();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.DrawImage(bufferImage, 0, 0);
}
}
}
オフスクリーンに同じオフスクリーンの内容をコピーしたいのですが
できますでしょうか?
やってみたのですができなかったのでもしできるなら教えてください
C#です。