码迷,mamicode.com
首页 > 其他好文 > 详细

主角带头发生成图xy

时间:2018-11-25 14:34:43      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:drawing   mes   ng2   生成   orb   component   com   names   offset   

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
Dictionary<string, string> dic1 = new Dictionary<string, string>();
Dictionary<string, string> dic2 = new Dictionary<string, string>();
bool bBmp = true;//是否bmp图
int startNum = 3600;//前起始编号
string before = "200";//后前缀编号
string bianzi = "0";
private void Form1_Load(object sender, EventArgs e)
{
}
public Form1()
{
int[] array = { 0, 1, 2, 3,
8, 9, 10, 11,
16, 17, 18, 19,
24, 25, 26, 27,
32, 33, 34, 35,
40, 41, 42, 43,
48, 49, 50, 51,
56, 57, 58, 59,
128,129,130,131,132,133,
136,137,138,139,140,141,
144,145,146,147,148,149,
152,153,154,155,156,157,
160,161,162,163,164,165,
168,169,170,171,172,173,
176,177,178,179,180,181,
184,185,186,187,188,189,

200,201,202,203,204,205,
208,209,210,211,212,213,
216,217,218,219,220,221,
224,225,226,227,228,229,
232,233,234,235,236,237,
240,241,242,243,244,245,
248,249,250,251,252,253,
256,257,258,259,260,261,

392,393,394,395,396,397,
400,401,402,403,404,405,
408,409,410,411,412,413,
416,417,418,419,420,421,
424,425,426,427,428,429,
432,433,434,435,436,437,
440,441,442,443,444,445,
448,449,450,451,452,453,

192,193,194,195,196,197,198,199,
};

if (!Directory.Exists("f:/github/legendzs/resource/b/" + before))
{
Directory.CreateDirectory("f:/github/legendzs/resource/b/" + before);
}

string result = "";
int stringlen = bBmp ? 6 : 5;
for (int i=0;i< array.Length; ++i)
{
string str = "" + (startNum + array[i]);
while (str.Length < stringlen) str = "0" + str;
String namenew = "" + i;
while (namenew.Length < 3) namenew = "0" + namenew;
namenew = before + namenew;
string path1 = "f:/github/legendzs/resource/a/" + before + "/" + str + (bBmp ? ".bmp" : ".PNG");
string path2 = "f:/github/legendzs/resource/b/" + before + "/" + namenew + ".png";
Image srcImage = Image.FromFile(path1);
string fileContent = File.ReadAllText("F:/github/legendzs/resource/a/" + before + "/Placements/" + str + ".txt");
int lastdot = fileContent.IndexOf("\r");
int a = int.Parse(fileContent.Substring(0, lastdot));
int b = int.Parse(fileContent.Substring(lastdot + 2, fileContent.Length - lastdot - 4));
double aa = a - 24 + srcImage.Width * 0.5;
double bb = 20 - b - srcImage.Height * 0.5;
dic1.Add(str, ""+aa+","+bb);
result += "\"" + namenew + "\" : \"" + aa + "," + bb + "\",\n";

 

str = "" + (2400 + array[i]);
while (str.Length < 6) str = "0" + str;
string path1Ex = "f:/github/legendzs/resource/a/bianzi" + bianzi + "/" + str + ".bmp";
srcImage = Image.FromFile(path1Ex);
fileContent = File.ReadAllText("F:/github/legendzs/resource/a/bianzi" + bianzi + "/Placements/" + str + ".txt");
lastdot = fileContent.IndexOf("\r");
a = int.Parse(fileContent.Substring(0, lastdot));
b = int.Parse(fileContent.Substring(lastdot + 2, fileContent.Length - lastdot - 4));
aa = a - 24 + srcImage.Width * 0.5;
bb = 20 - b - srcImage.Height * 0.5;
dic2.Add(str, "" + aa + "," + bb);


modifyToPng(path1, path1Ex, path2);
}
File.AppendAllText("f:/1.txt", result);
}


public void modifyToPng(string sf, string sf2, string sf3)
{
Image srcImage = Image.FromFile(sf);
int resW = srcImage.Width;
int resH = srcImage.Height;
Bitmap resultImage = new Bitmap(resW, resH);
Graphics gg = Graphics.FromImage(resultImage);
gg.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed;
gg.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
gg.DrawImage(srcImage, new Rectangle(0, 0, resW, resH), new Rectangle(0, 0, srcImage.Width, srcImage.Height), GraphicsUnit.Pixel);

Image srcImage2 = Image.FromFile(sf2);
int resW2 = srcImage2.Width;
int resH2 = srcImage2.Height;
Bitmap resultImage2 = new Bitmap(resW2, resH2);
Graphics gg2 = Graphics.FromImage(resultImage2);
gg2.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed;
gg2.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
gg2.DrawImage(srcImage2, new Rectangle(0, 0, resW2, resH2), new Rectangle(0, 0, srcImage2.Width, srcImage2.Height), GraphicsUnit.Pixel);

string str = dic1[sf.Substring(sf.LastIndexOf("/") + 1, bBmp ? 6 : 5)];
int offsetx1 = (int)double.Parse(str.Split(‘,‘)[0]);
int offsety1 = (int)double.Parse(str.Split(‘,‘)[1]);
int x = offsetx1 - resW / 2;
int y = offsety1 - resH / 2;
int xx = offsetx1 + resW / 2;
int yy = offsety1 + resH / 2;

string str2 = dic2[sf2.Substring(sf2.LastIndexOf("/") + 1, 6)];
int offsetx2 = (int)double.Parse(str2.Split(‘,‘)[0]);
int offsety2 = (int)double.Parse(str2.Split(‘,‘)[1]);
int x2 = offsetx2 - resW2 / 2;
int y2 = offsety2 - resH2 / 2;
int xx2 = offsetx2 + resW2 / 2;
int yy2 = offsety2 + resH2 / 2;


for (int i = 0; i < resW2; i++)
{
for (int j = 0; j < resH2; j++)
{
Color c2 = resultImage2.GetPixel(i, j);
if(c2.R!=0 || c2.G!=0 || c2.B != 0)
{
if(i + x2 - x<resW && j + yy - yy2 < resH && j + yy - yy2>=0)
{
resultImage.SetPixel(i + x2 - x, j + yy - yy2, c2);
}
}
}
}

for (int i = 0; i < resW; i++)
{
for (int j = 0; j < resH; j++)
{
Color c = resultImage.GetPixel(i, j);
int a = (c.R == 0 && c.G == 0 && c.B == 0) ? 0 : 255;
resultImage.SetPixel(i, j, Color.FromArgb(a, c));
}
}
resultImage.Save(sf3, System.Drawing.Imaging.ImageFormat.Png);
}

double crCalculateBlend(double a1, double a2, double c1, double c2)
{
if (a1 + a2 - a1 * a2 == 0) return 0;
return (c1 * a1 * (1.0 - a2) + c2 * a2) / (a1 + a2 - a1 * a2);
}

public Color crColorBlend(Color cor1, Color cor2)
{
double fAlp1 = cor1.A / 255.0;
double fAlp2 = cor2.A / 255.0;
double fAlpBlend = fAlp1 + fAlp2 - fAlp1 * fAlp2;

double fRed1 = cor1.R / 255.0;
double fRed2 = cor2.R / 255.0;
double fRedBlend = crCalculateBlend(fAlp1, fAlp2, fRed1, fRed2);

double fGreen1 = cor1.G / 255.0;
double fGreen2 = cor2.G / 255.0;
double fGreenBlend = crCalculateBlend(fAlp1, fAlp2, fGreen1, fGreen2);

double fBlue1 = cor1.B / 255.0;
double fBlue2 = cor2.B / 255.0;
double fBlueBlend = crCalculateBlend(fAlp1, fAlp2, fBlue1, fBlue2);

return Color.FromArgb((int)(fAlpBlend * 255), (int)(fRedBlend * 255), (int)(fGreenBlend * 255), (int)(fBlueBlend * 255));
}

}
}

 

主角带头发生成图xy

标签:drawing   mes   ng2   生成   orb   component   com   names   offset   

原文地址:https://www.cnblogs.com/agchuanqi/p/10015351.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!