效果如下:
方法如下:
记得引用
using System.Drawing; using System.Drawing.Imaging;
public string CreateGroupLogo() { //头像个数 int Num = Convert.ToInt32(RequestFormat("n")); string SavePath = Server.MapPath("/Content/Apps/GroupLogo/"); string LogoName = "Grouplogo.png"; //新建一个底层图层 int width = 200, height = 200; Bitmap RawBm = new Bitmap(width, height); Graphics g = Graphics.FromImage(RawBm); // 底色设置 g.Clear(Color.Gray); //定义一个区域 int rWidth = 50, rHeight = 50; Rectangle rg = new Rectangle(0, 0, rWidth, rHeight); //头像个数 switch (Num) { case 1: Rectangle rg1 = new Rectangle(50, 50, 100, 100); Bitmap bm1 = new Bitmap(SavePath + "1.jpg"); g.DrawImage(bm1, rg1); RawBm.Save(SavePath + LogoName, ImageFormat.Png); break; case 2: Rectangle rg2_1 = new Rectangle(7, 55, 90, 90); Bitmap bm2_1 = new Bitmap(SavePath + "1.jpg"); Rectangle rg2_2 = new Rectangle(104, 55, 90, 90); Bitmap bm2_2 = new Bitmap(SavePath + "1.jpg"); g.DrawImage(bm2_1, rg2_1); g.DrawImage(bm2_2, rg2_2); RawBm.Save(SavePath + LogoName, ImageFormat.Png); break; case 3: Rectangle rg3_1 = new Rectangle(55, 7, 90, 90); Bitmap bm3_1 = new Bitmap(SavePath + "1.jpg"); Rectangle rg3_2 = new Rectangle(7, 105, 90, 90); Bitmap bm3_2 = new Bitmap(SavePath + "1.jpg"); Rectangle rg3_3 = new Rectangle(104, 105, 90, 90); Bitmap bm3_3 = new Bitmap(SavePath + "1.jpg"); g.DrawImage(bm3_1, rg3_1); g.DrawImage(bm3_2, rg3_2); g.DrawImage(bm3_3, rg3_3); RawBm.Save(SavePath + LogoName, ImageFormat.Png); break; case 4: Rectangle rg4_1 = new Rectangle(7, 7, 90, 90); Bitmap bm4_1 = new Bitmap(SavePath + "1.jpg"); Rectangle rg4_2 = new Rectangle(104, 7, 90, 90); Bitmap bm4_2 = new Bitmap(SavePath + "1.jpg"); Rectangle rg4_3 = new Rectangle(7, 105, 90, 90); Bitmap bm4_3 = new Bitmap(SavePath + "1.jpg"); Rectangle rg4_4 = new Rectangle(104, 105, 90, 90); Bitmap bm4_4 = new Bitmap(SavePath + "1.jpg"); g.DrawImage(bm4_1, rg4_1); g.DrawImage(bm4_2, rg4_2); g.DrawImage(bm4_3, rg4_3); g.DrawImage(bm4_4, rg4_4); RawBm.Save(SavePath + LogoName, ImageFormat.Png); break; case 5: Rectangle rg5_1 = new Rectangle(38, 35, 60, 60); Bitmap bm5_1 = new Bitmap(SavePath + "1.jpg"); Rectangle rg5_2 = new Rectangle(103, 35, 60, 60); Bitmap bm5_2 = new Bitmap(SavePath + "1.jpg"); Rectangle rg5_3 = new Rectangle(5, 105, 60, 60); Bitmap bm5_3 = new Bitmap(SavePath + "1.jpg"); Rectangle rg5_4 = new Rectangle(70, 105, 60, 60); Bitmap bm5_4 = new Bitmap(SavePath + "1.jpg"); Rectangle rg5_5 = new Rectangle(135, 105, 60, 60); Bitmap bm5_5 = new Bitmap(SavePath + "1.jpg"); g.DrawImage(bm5_1, rg5_1); g.DrawImage(bm5_2, rg5_2); g.DrawImage(bm5_3, rg5_3); g.DrawImage(bm5_4, rg5_4); g.DrawImage(bm5_5, rg5_5); RawBm.Save(SavePath + LogoName, ImageFormat.Png); break; case 6: Rectangle rg6_1 = new Rectangle(5, 38, 60, 60); Bitmap bm6_1 = new Bitmap(SavePath + "1.jpg"); Rectangle rg6_2 = new Rectangle(70, 38, 60, 60); Bitmap bm6_2 = new Bitmap(SavePath + "1.jpg"); Rectangle rg6_3 = new Rectangle(135, 38, 60, 60); Bitmap bm6_3 = new Bitmap(SavePath + "1.jpg"); Rectangle rg6_4 = new Rectangle(5, 104, 60, 60); Bitmap bm6_4 = new Bitmap(SavePath + "1.jpg"); Rectangle rg6_5 = new Rectangle(70, 104, 60, 60); Bitmap bm6_5 = new Bitmap(SavePath + "1.jpg"); Rectangle rg6_6 = new Rectangle(135, 104, 60, 60); Bitmap bm6_6 = new Bitmap(SavePath + "1.jpg"); g.DrawImage(bm6_1, rg6_1); g.DrawImage(bm6_2, rg6_2); g.DrawImage(bm6_3, rg6_3); g.DrawImage(bm6_4, rg6_4); g.DrawImage(bm6_5, rg6_5); g.DrawImage(bm6_6, rg6_6); RawBm.Save(SavePath + LogoName, ImageFormat.Png); break; case 7: Rectangle rg7_1 = new Rectangle(70, 5, 60, 60); Bitmap bm7_1 = new Bitmap(SavePath + "1.jpg"); Rectangle rg7_2 = new Rectangle(5, 70, 60, 60); Bitmap bm7_2 = new Bitmap(SavePath + "1.jpg"); Rectangle rg7_3 = new Rectangle(70, 70, 60, 60); Bitmap bm7_3 = new Bitmap(SavePath + "1.jpg"); Rectangle rg7_4 = new Rectangle(135, 70, 60, 60); Bitmap bm7_4 = new Bitmap(SavePath + "1.jpg"); Rectangle rg7_5 = new Rectangle(5, 135, 60, 60); Bitmap bm7_5 = new Bitmap(SavePath + "1.jpg"); Rectangle rg7_6 = new Rectangle(70, 135, 60, 60); Bitmap bm7_6 = new Bitmap(SavePath + "1.jpg"); Rectangle rg7_7 = new Rectangle(135, 135, 60, 60); Bitmap bm7_7 = new Bitmap(SavePath + "1.jpg"); g.DrawImage(bm7_1, rg7_1); g.DrawImage(bm7_2, rg7_2); g.DrawImage(bm7_3, rg7_3); g.DrawImage(bm7_4, rg7_4); g.DrawImage(bm7_5, rg7_5); g.DrawImage(bm7_6, rg7_6); g.DrawImage(bm7_7, rg7_7); RawBm.Save(SavePath + LogoName, ImageFormat.Png); break; case 8: Rectangle rg8_1 = new Rectangle(38, 5, 60, 60); Bitmap bm8_1 = new Bitmap(SavePath + "1.jpg"); Rectangle rg8_2 = new Rectangle(103, 5, 60, 60); Bitmap bm8_2 = new Bitmap(SavePath + "1.jpg"); Rectangle rg8_3 = new Rectangle(5, 70, 60, 60); Bitmap bm8_3 = new Bitmap(SavePath + "1.jpg"); Rectangle rg8_4 = new Rectangle(70, 70, 60, 60); Bitmap bm8_4 = new Bitmap(SavePath + "1.jpg"); Rectangle rg8_5 = new Rectangle(135, 70, 60, 60); Bitmap bm8_5 = new Bitmap(SavePath + "1.jpg"); Rectangle rg8_6 = new Rectangle(5, 135, 60, 60); Bitmap bm8_6 = new Bitmap(SavePath + "1.jpg"); Rectangle rg8_7 = new Rectangle(70, 135, 60, 60); Bitmap bm8_7 = new Bitmap(SavePath + "1.jpg"); Rectangle rg8_8 = new Rectangle(135, 135, 60, 60); Bitmap bm8_8 = new Bitmap(SavePath + "1.jpg"); g.DrawImage(bm8_1, rg8_1); g.DrawImage(bm8_2, rg8_2); g.DrawImage(bm8_3, rg8_3); g.DrawImage(bm8_4, rg8_4); g.DrawImage(bm8_5, rg8_5); g.DrawImage(bm8_6, rg8_6); g.DrawImage(bm8_7, rg8_7); g.DrawImage(bm8_8, rg8_8); RawBm.Save(SavePath + LogoName, ImageFormat.Png); break; case 9: Rectangle rg9_1 = new Rectangle(5, 5, 60, 60); Bitmap bm9_1 = new Bitmap(SavePath + "1.jpg"); Rectangle rg9_2 = new Rectangle(70, 5, 60, 60); Bitmap bm9_2 = new Bitmap(SavePath + "1.jpg"); Rectangle rg9_3 = new Rectangle(135, 5, 60, 60); Bitmap bm9_3 = new Bitmap(SavePath + "1.jpg"); Rectangle rg9_4 = new Rectangle(5, 70, 60, 60); Bitmap bm9_4 = new Bitmap(SavePath + "1.jpg"); Rectangle rg9_5 = new Rectangle(70, 70, 60, 60); Bitmap bm9_5 = new Bitmap(SavePath + "1.jpg"); Rectangle rg9_6 = new Rectangle(135, 70, 60, 60); Bitmap bm9_6 = new Bitmap(SavePath + "1.jpg"); Rectangle rg9_7 = new Rectangle(5, 135, 60, 60); Bitmap bm9_7 = new Bitmap(SavePath + "1.jpg"); Rectangle rg9_8 = new Rectangle(70, 135, 60, 60); Bitmap bm9_8 = new Bitmap(SavePath + "1.jpg"); Rectangle rg9_9 = new Rectangle(135, 135, 60, 60); Bitmap bm9_9 = new Bitmap(SavePath + "1.jpg"); g.DrawImage(bm9_1, rg9_1); g.DrawImage(bm9_2, rg9_2); g.DrawImage(bm9_3, rg9_3); g.DrawImage(bm9_4, rg9_4); g.DrawImage(bm9_5, rg9_5); g.DrawImage(bm9_6, rg9_6); g.DrawImage(bm9_7, rg9_7); g.DrawImage(bm9_8, rg9_8); g.DrawImage(bm9_9, rg9_9); RawBm.Save(SavePath + LogoName, ImageFormat.Png); break; default: break; } return ""; }