我想在一个有2列的图像中合并10个图像,每列包含5个图像 [英] I want to merge 10 images in one image having 2 columns and each column contains 5 images

查看:71
本文介绍了我想在一个有2列的图像中合并10个图像,每列包含5个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想在一张图片中插入10张图片,图片大小为A4,有2列,每列包含5张图片。我不知道该怎么做。我搜索了大多数网站但没有任何作用。任何建议或示例代码请帮助我...



我做了以下代码:



< pre lang =c#>图像[] img = new 图像[ 10 ];
for int i = 0 ; i< img.Length; i ++)
{
img [i] = Image.FromFile(dir [i] .ToString());
}
使用(图形g = Graphics.FromImage(位图))
{

g。 DrawImage(img [ 0 ], 300 0 );


g.DrawImage(img [ 1 ], 300 300 );
g.DrawImage(img [ 2 ], 300 ,img [ 2 ]。高度+ 100 );
g.DrawImage(img [ 3 ],img [ 3 ]。宽度+ 400 ,img [ 3 ]。高度+ 100 );
g.DrawImage(img [ 4 ], 300 ,img [ 0 ]。高度+ img [ 4 ]。高度+ 300 );
g.DrawImage(img [ 5 ],img [ 4 ]。宽度+ 400 ,img [ 1 ]。高度+ img [ 3 ]。高度+ 500 );
g.DrawImage(img [ 6 ], 300 ,img [ 0 ]。高度+ img [ 2 ]。高度+ img [ 4 ]。高度+ 500 );
g.DrawImage(img [ 7 ],img [ 6 ]。宽度+ 400 ,img [ 1 ]。高度+ img [ 3 ]。高度+ img [ 5 ]。高度+ 500 );
g.DrawImage(img [ 8 ], 300 ,img [ 0 ]。高度+ img [ 2 ]。高度+ img [ 4 ]。高度+ img [ 6 ]。高度+ 500 );
g.DrawImage(img [ 9 ],img [ 8 ]。宽度+ 400 ,img [ 1 ]。高度+ img [ 3 ]。高度+ img [ 5 ]。高度+ img [ 7 ]。高度+ 500
}
bitmap.Save( D:\\ranjitpure.jpg);



这里我手动设置图像。

解决方案

如果您是C#的新手,那么这可能是一个相当雄心勃勃的项目。我建议通过 MSDN教程 [ ^ ],并查看其中一些 CodeProject文章 [ ^ ]。


大家使用以下代码执行上述任务。



图像[] img =新图像[10];

FolderBrowserDialog fld = new FolderBrowserDialog ();

////////此代码用于选择图像文件的文件夹////////

if(fld.ShowDialog( )== DialogResult.OK)

{

dir = Directory.GetFiles(fld.SelectedPath);

}



//////此代码用于为图像对象分配图像路径/////////

for(int i = 0;我< img.Length; i ++)

{

img [i] = Image.FromFile(dir [i] .ToString());

}

for(int i = 0; i< img.Length; i ++)

{

mywidht = mywidht + img [i] .Width;

myheight = myheight + img [i] .Height;

}



位图myBitmap =新位图(13000) ,13500);

myBitmap.SetResolution(800,600);

int num = 0;



使用(图形g = Graphics.FromImage(myBitmap))

{

g.Clear(Color.White);

////// ///用于在单张图像上合并10张图像的自动图像设置代码/////////////////////////

for(int x = 0; x <5; x ++)

{

for(int y = 0; y< 2; y ++)

{

int chunkWidth = img [num] .Width + 3500;

int chunkHeight = img [num] .Height + 1000;

g .DrawImage(img [num],new Rectangle(chunkWidth * y + 300,chunkHeight * x + 100,img [num] .Width + 2800,img [num] .Height + 1200),new Rectangle(0,0,img) [num] .Width,img [num] .Height + 200),GraphicsUnit.Pixel);

num ++;

}

}

g.Dispose();

}



myBitmap.Save(@D:\\ myoutput.jpg,ImageFormat.Jpeg);

myBitmap.Dispose();

MessageBox.Show(Image Created);


Hi,
I want to insert 10 images in one image having size A4 with 2 columns and each column contains 5 images. I dont know how to do that. I googled most site's but nothing works. Any suggestions or sample code please help me...

I did the following code :

Image[] img = new Image[10];
for(int i=0;i<img.Length;i++)
{
   img[i] = Image.FromFile(dir[i].ToString());
}
using (Graphics g = Graphics.FromImage(bitmap))
{

g.DrawImage(img[0], 300, 0);


    g.DrawImage(img[1], 300, 300);
    g.DrawImage(img[2], 300, img[2].Height + 100);
    g.DrawImage(img[3], img[3].Width + 400, img[3].Height + 100);
    g.DrawImage(img[4], 300, img[0].Height + img[4].Height + 300);
    g.DrawImage(img[5], img[4].Width + 400, img[1].Height + img[3].Height + 500);
    g.DrawImage(img[6], 300, img[0].Height + img[2].Height + img[4].Height + 500);
    g.DrawImage(img[7], img[6].Width + 400, img[1].Height + img[3].Height           +          img[5].Height + 500);
    g.DrawImage(img[8], 300, img[0].Height + img[2].Height + img[4].Height + img[6].Height + 500);
    g.DrawImage(img[9], img[8].Width + 400, img[1].Height + img[3].Height + img[5].Height + img[7].Height + 500
}
bitmap.Save("D:\\ranjitpure.jpg");


Here I set images manually.

解决方案

If you are new to C# then this may be a rather ambitious project. I would suggest working through the MSDN tutorials[^], and also looking at some of these CodeProject articles[^].


Guys use following code for doing above task.

Image[] img = new Image[10];
FolderBrowserDialog fld = new FolderBrowserDialog();
//////// This code is for selecting folder for image files ////////
if (fld.ShowDialog() == DialogResult.OK)
{
dir = Directory.GetFiles(fld.SelectedPath);
}

////// This code is for assigning image path to image object /////////
for (int i = 0; i < img.Length; i++)
{
img[i] = Image.FromFile(dir[i].ToString());
}
for (int i = 0; i < img.Length; i++)
{
mywidht = mywidht + img[i].Width;
myheight = myheight + img[i].Height;
}

Bitmap myBitmap = new Bitmap(13000,13500);
myBitmap.SetResolution(800,600);
int num = 0;

using (Graphics g = Graphics.FromImage(myBitmap))
{
g.Clear(Color.White);
///////// Automatic image set code for merging 10 images on single image /////////////////////////
for (int x = 0; x < 5; x++)
{
for (int y = 0; y < 2; y++)
{
int chunkWidth = img[num].Width + 3500;
int chunkHeight = img[num].Height + 1000;
g.DrawImage(img[num], new Rectangle(chunkWidth * y +300, chunkHeight * x + 100, img[num].Width+2800, img[num].Height+1200), new Rectangle(0,0, img[num].Width, img[num].Height+200), GraphicsUnit.Pixel);
num++;
}
}
g.Dispose();
}

myBitmap.Save(@"D:\\myoutput.jpg", ImageFormat.Jpeg);
myBitmap.Dispose();
MessageBox.Show("Image Created");


这篇关于我想在一个有2列的图像中合并10个图像,每列包含5个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆