我每张图是90*56大小一至,按一定顺序排,每排排9张图,排两排,不重叠.在c#里要怎么写啊
我每张图是90*56大小一至,按一定顺序排,每排排9张图,排两排,不重叠.在c#里要怎么写啊有高手能知诉我吗 --------------------编程问答-------------------- 不知道你要怎么排……
或者说,不知道你要排在哪
假如是在winform上,可以new pictureBox,从(0,0)坐标开始 每次坐标加(90,0)
换行坐标再加(0,56),设置大小为(90,56)
应该没什么难度吧 --------------------编程问答-------------------- 可以的话先在画面上放好pictureBox,之后再通过程序指定图片 --------------------编程问答-------------------- 关键是LZ以后还有什么操作,如果仅仅是显示,不如将这18张图分两排直接画在一个Image里. --------------------编程问答-------------------- OpenFileDialog of = new OpenFileDialog();
of.Multiselect = true;
of.Filter = "jpg文件;asdfsad;asdfsa|*.jpg|bmp文件|*.bmp|gif文件|*.gif";
if (of.ShowDialog() == DialogResult.OK)
{
string[] files = of.FileNames;
Image img = new Bitmap(Image.FromFile(files[0]).Width * 2, Image.FromFile(files[0]).Height * 2);
if (files.Length >= 2 * 2)
{
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
Graphics g = Graphics.FromImage(img);
g.DrawImage(Image.FromFile(files[i * j]), (j * Image.FromFile(files[i * j]).Width), (i * Image.FromFile(files[i * j]).Height));
PictureBox pp = new PictureBox();
pp.Image = img;
}
}
img.Save("all.png", System.Drawing.Imaging.ImageFormat.Png);
}
else
{
MessageBox.Show("选择的图片小于81张");
}
}
假设这个要怎么改啊 --------------------编程问答-------------------- private void Form1_Load(object sender, EventArgs e)
{
OpenFileDialog of = new OpenFileDialog();
of.Multiselect = true;
of.Filter = "jpg文件;asdfsad;asdfsa|*.jpg|bmp文件|*.bmp|gif文件|*.gif";
PictureBox pp = new PictureBox();
if (of.ShowDialog() == DialogResult.OK)
{
string[] files = of.FileNames;
int cols=0;
if (files.Length % 2 == 1)
cols = files.Length / 2 + 1;
else
cols = files.Length / 2;
int w=Image.FromFile(files[0]).Width;
int h=Image.FromFile(files[0]).Height;
Image img = new Bitmap(Image.FromFile(files[0]).Width * cols, Image.FromFile(files[0]).Height * 2);
pp.Size = img.Size;
pp.Image = img;
if (files.Length >=18)
{
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < cols; j++)
{
Graphics g = Graphics.FromImage(img);
Rectangle r=new Rectangle(new Point(j*w,i*h),new Size(w,h));
g.DrawImage(Image.FromFile(files[i * cols + j]), r);
}
}
img.Save("all.png", System.Drawing.Imaging.ImageFormat.Png);
}
else
{
MessageBox.Show("选择的图片小于81张");
}
this.Controls.Add(pp);
}
} --------------------编程问答-------------------- 修改了一点.每排排9张
private void Form1_Load(object sender, EventArgs e)
{
OpenFileDialog of = new OpenFileDialog();
of.Multiselect = true;
of.Filter = "jpg文件;asdfsad;asdfsa|*.jpg|bmp文件|*.bmp|gif文件|*.gif";
PictureBox pp = new PictureBox();
if (of.ShowDialog() == DialogResult.OK)
{
string[] files = of.FileNames;
int w=Image.FromFile(files[0]).Width;
int h=Image.FromFile(files[0]).Height;
Image img = new Bitmap(Image.FromFile(files[0]).Width * 9, Image.FromFile(files[0]).Height * 2);
pp.Size = img.Size;
pp.Image = img;
if (files.Length <=18)
{
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 9; j++)
{
if ((i * 9 + j) >= files.Length)
break;
Graphics g = Graphics.FromImage(img);
Rectangle r=new Rectangle(new Point(j*w,i*h),new Size(w,h));
g.DrawImage(Image.FromFile(files[i * 9 + j]), r);
}
}
img.Save("all.png", System.Drawing.Imaging.ImageFormat.Png);
}
else
{
MessageBox.Show("选择的图片小于81张");
}
this.Controls.Add(pp);
}
}
补充:.NET技术 , C#