<?xml version="1.0" encoding="utf-8" ?><contacts><contactid='1'><firstName>Michael</firstName><lastName>Jordan</lastName><age>40</age><dob>1965</dob><salary>100.35</salary></contact><contactid='2'><firstName>Scottie</firstName><lastName>Pippen</lastName><age>38</age><dob>1967</dob><salary>55.28</salary></contact></contacts>publicclass XmlToDynamic
{
publicstaticvoid Parse(dynamic parent, XElement node)
{
if (node.HasElements)
{
if (node.Elements(node.Elements().First().Name.LocalName).Count() > 1)
{
//list var item = new ExpandoObject();
var list = new List<dynamic>();
foreach (var element in node.Elements())
{
Parse(list, element);
}
AddProperty(item, node.Elements().First().Name.LocalName, list);…
This code will crop the image based on all white and transparent pixels from around the imagepublicstatic Bitmap CropWhiteSpace(Bitmap bmp)
{
int w = bmp.Width;
int h = bmp.Height;
int white = 0xffffff;
Func<int, bool> allWhiteRow = r =>
{
for (int i = 0; i < w; ++i)
if ((bmp.GetPixel(i, r).ToArgb() & white) != white)
returnfalse;
returntrue;
};
Func<int, bool> allWhiteColumn = c =>
{
for (int i = 0; i < h; ++i)
if ((bmp.GetPixel(c, i).ToArgb() & white) != white)
returnfalse;
returntrue;
};
int topmost = 0;
for (int row = 0; row < h; ++row)
{
if (!allWhiteRow(row))
break;
topmost = row;
}
int bottommost = 0;
for (int row = h - 1; row >= 0; --row)
{
if (!allWhiteRow(row))
break;
bottommost = row;
}
int leftmost = 0, rightmost = 0;
for (int col = 0; col < w; ++col)
{
if (!allWhiteColumn(col))
break;
leftmost = col;
Comments
Post a Comment