kopia lustrzana https://github.com/njcrawford/EmbroideryReader
Try to make designToBitmap() a little more efficient, remove a redundant calculation for debug info stitch length
rodzic
daa67cfcdd
commit
39cdbbda3f
|
@ -381,9 +381,7 @@ namespace PesFile
|
||||||
outfile.WriteLine("unknown start byte: " + thisBlock.unknownStartByte.ToString("X2"));
|
outfile.WriteLine("unknown start byte: " + thisBlock.unknownStartByte.ToString("X2"));
|
||||||
foreach (Stitch thisStitch in thisBlock.stitches)
|
foreach (Stitch thisStitch in thisBlock.stitches)
|
||||||
{
|
{
|
||||||
double stitchLength;
|
string tempLine = thisStitch.a.ToString() + " - " + thisStitch.b.ToString() + ", length " + thisStitch.calcLength();
|
||||||
stitchLength = Math.Sqrt(Math.Pow(thisStitch.a.X - thisStitch.b.X, 2) + Math.Pow(thisStitch.a.Y - thisStitch.b.Y, 2));
|
|
||||||
string tempLine = thisStitch.a.ToString() + " - " + thisStitch.b.ToString() + ", length " + stitchLength;
|
|
||||||
if (thisStitch.extraBits1 != 0x00)
|
if (thisStitch.extraBits1 != 0x00)
|
||||||
{
|
{
|
||||||
tempLine += " (extra bits 1: " + thisStitch.extraBits1.ToString("X2") + ")";
|
tempLine += " (extra bits 1: " + thisStitch.extraBits1.ToString("X2") + ")";
|
||||||
|
@ -430,14 +428,18 @@ namespace PesFile
|
||||||
|
|
||||||
public Bitmap designToBitmap(Single threadThickness, bool filterUglyStitches, double filterUglyStitchesThreshold, float scale)
|
public Bitmap designToBitmap(Single threadThickness, bool filterUglyStitches, double filterUglyStitchesThreshold, float scale)
|
||||||
{
|
{
|
||||||
Bitmap DrawArea;
|
|
||||||
Graphics xGraph;
|
|
||||||
int imageWidth = (int)((GetWidth() + (threadThickness * 2)) * scale);
|
int imageWidth = (int)((GetWidth() + (threadThickness * 2)) * scale);
|
||||||
int imageHeight = (int)((GetHeight() + (threadThickness * 2)) * scale);
|
int imageHeight = (int)((GetHeight() + (threadThickness * 2)) * scale);
|
||||||
float tempThreadThickness = threadThickness * scale;
|
float tempThreadThickness = threadThickness * scale;
|
||||||
|
|
||||||
DrawArea = new Bitmap(imageWidth, imageHeight);
|
Bitmap DrawArea = new Bitmap(imageWidth, imageHeight);
|
||||||
using (xGraph = Graphics.FromImage(DrawArea))
|
// Return now if for any reason there aren't any blocks
|
||||||
|
if(blocks.Count == 0)
|
||||||
|
{
|
||||||
|
return DrawArea;
|
||||||
|
}
|
||||||
|
|
||||||
|
using (Graphics xGraph = Graphics.FromImage(DrawArea))
|
||||||
{
|
{
|
||||||
int translateX = (int)(translateStart.X * scale);
|
int translateX = (int)(translateStart.X * scale);
|
||||||
int translateY = (int)(translateStart.Y * scale);
|
int translateY = (int)(translateStart.Y * scale);
|
||||||
|
@ -446,15 +448,20 @@ namespace PesFile
|
||||||
// Draw smoother lines
|
// Draw smoother lines
|
||||||
xGraph.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
|
xGraph.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
|
||||||
|
|
||||||
for (int i = 0; i < blocks.Count; i++)
|
// Only use one pen - I think this will be more resource friendly than creating a new pen for each block
|
||||||
|
using (Pen tempPen = new Pen(blocks[0].color, tempThreadThickness))
|
||||||
{
|
{
|
||||||
using (Pen tempPen = new Pen(blocks[i].color, tempThreadThickness))
|
// Set rounded ends and joints
|
||||||
{
|
tempPen.StartCap = System.Drawing.Drawing2D.LineCap.Round;
|
||||||
tempPen.StartCap = System.Drawing.Drawing2D.LineCap.Round;
|
tempPen.EndCap = System.Drawing.Drawing2D.LineCap.Round;
|
||||||
tempPen.EndCap = System.Drawing.Drawing2D.LineCap.Round;
|
tempPen.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;
|
||||||
tempPen.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;
|
|
||||||
|
|
||||||
foreach (Stitch thisStitch in blocks[i].stitches)
|
foreach(StitchBlock thisBlock in blocks)
|
||||||
|
{
|
||||||
|
// Set new color for this block
|
||||||
|
tempPen.Color = thisBlock.color;
|
||||||
|
|
||||||
|
foreach (Stitch thisStitch in thisBlock.stitches)
|
||||||
{
|
{
|
||||||
if (filterUglyStitches && // Check for filter ugly stitches option
|
if (filterUglyStitches && // Check for filter ugly stitches option
|
||||||
!formatWarning && // Only filter stitches if we think we understand the format
|
!formatWarning && // Only filter stitches if we think we understand the format
|
||||||
|
|
Ładowanie…
Reference in New Issue