public void RotateFlip(bool horizontalFlip, bool verticalFlip, RotateAngle angle) { this.mBmp = BitmapHelper.RotateFlip(this.mBmp, horizontalFlip, verticalFlip, angle); this.mPointsWidth = this.mBmp.Width; this.mPointsHeight = this.mBmp.Height; this.Invalidate(); }
public static void SaveToXml(Bitmap sourceBitmap, XmlNode node, XmlSavingOptions options) { Bitmap bmp = BitmapHelper.RotateFlip(sourceBitmap, options.FlipHorizontal, options.FlipVertical, options.Angle); if (options.Inverse) { bmp = BitmapHelper.Inverse(bmp); } if ((bmp.Width % 8) != 0) { if (options.AlignRight) { bmp = BitmapHelper.Resize(bmp, 8 - bmp.Width % 8, 0, 0, 0); } } //separate node for bitmap's data //XmlNode nodeBitmap = node.AppendChild(node.OwnerDocument.CreateElement("bitmap")); XmlNode nodeBitmap = node; //bitmap info (nodeBitmap as XmlElement).SetAttribute("width", Convert.ToString(sourceBitmap.Width, CultureInfo.InvariantCulture)); (nodeBitmap as XmlElement).SetAttribute("height", Convert.ToString(sourceBitmap.Height, CultureInfo.InvariantCulture)); //preview node, all bits at one line XmlNode nodePreview = nodeBitmap.AppendChild(node.OwnerDocument.CreateElement("preview")); BitmapData bmd = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format1bppIndexed); for (int y = 0; y < bmp.Height; y++) { //bitmap's line XmlNode nodeLine = nodeBitmap.AppendChild(node.OwnerDocument.CreateElement("line")); (nodeLine as XmlElement).SetAttribute("index", Convert.ToString(y, CultureInfo.InvariantCulture)); StringBuilder byteData = new StringBuilder(); StringBuilder lineData = new StringBuilder(); for (int x = 0; x < bmp.Width; x++) { //if (bmp.GetPixel(x, y).GetBrightness() > this.mBrightnessEdge) if (BitmapHelper.GetPixel(bmd, x, y)) { byteData.Append("1"); } else { byteData.Append("0"); } //if byte filled or end of line if ((x % 8) == 7 || x == (bmp.Width - 1)) { XmlNode nodeColumn = nodeLine.AppendChild(node.OwnerDocument.CreateElement("column")); (nodeColumn as XmlElement).SetAttribute("index", Convert.ToString((int)(x / 8), CultureInfo.InvariantCulture)); //ensure what 8 bits (1 byte) while (byteData.Length < 8) { byteData.Append("0"); } nodeColumn.InnerText = byteData.ToString(); lineData.Append(byteData); if (options.MirrorEachByte) { string str = byteData.ToString(); byteData.Length = 0; foreach (char c in str) { byteData.Insert(0, c); } nodeColumn.InnerText = byteData.ToString(); } byteData.Length = 0; } } lineData = lineData.Replace('0', '_').Replace('1', '#'); XmlNode nodePreviewLine = nodePreview.AppendChild(node.OwnerDocument.CreateElement("line")); nodePreviewLine.InnerText = lineData.ToString(); } bmp.UnlockBits(bmd); }