图片位置偏移处理

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
{

private void Form1_Load(object sender, EventArgs e)
{

}


public Form1()
{
InitializeComponent();


string result = "";
int j = 0;
FileSystemInfo[] files = (new DirectoryInfo("f:/ggg/") as DirectoryInfo).GetFileSystemInfos();
for (int i = 0; i < files.Length; ++i)
{
Console.WriteLine("" + i);
FileInfo file = files[i] as FileInfo;
if (file != null)
{
if (file.FullName.Substring(file.FullName.LastIndexOf(".")) == ".png")
{
string sf = file.FullName;
Image srcImage = Image.FromFile(sf);
Bitmap resultImage = new Bitmap(srcImage);

FileSystemInfo[] files2 = (new DirectoryInfo("f:/ddd/") as DirectoryInfo).GetFileSystemInfos();
for (; j < files2.Length; ++j)
{
FileInfo file2 = files2[j] as FileInfo;
if (file2 != null)
{
if (file2.FullName.Substring(file2.FullName.LastIndexOf(".")) == ".bmp")
{
string sf2 = file2.FullName;
Image srcImage2 = Image.FromFile(sf2);
if (equal(srcImage, srcImage2, resultImage))
{
string fileContent = File.ReadAllText("F:\\ddd\\Placements\\" + sf2.Substring(7, 6) + ".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;

result += "\"" + sf.Substring(7, 6) + "\" : \"" + aa + "," + bb + "\",\n";
++j;
break;
}
}
}
}
}
}
}
File.WriteAllText("f:\\1.txt", result);

}


public bool equal(Image srcImage, Image srcImage2, Bitmap resultImage)
{
int resW = srcImage.Width;
int resH = srcImage.Height;
int resW2 = srcImage2.Width;
int resH2 = srcImage2.Height;
Bitmap resultImage2 = new Bitmap(srcImage2);
if (resW == resW2 && resH == resH2)
{
for (int i = 0; i < resW; i++)
{
for (int j = 0; j < resH; j++)
{
Color c = resultImage.GetPixel(i, j);
Color c2 = resultImage2.GetPixel(i, j);
if (c2.R == 0 && c2.G == 0 && c2.B == 0)
{
if (c.A != 0)
{
return false;
}
}
}
}
}
else
{
return false;
}
return true;
}
}
}

转载于:https://www.cnblogs.com/agchuanqi/p/7857880.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值