本文整理汇总了C#中Bitmap.DrawLine方法的典型用法代码示例。如果您正苦于以下问题:C# Bitmap.DrawLine方法的具体用法?C# Bitmap.DrawLine怎么用?C# Bitmap.DrawLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bitmap
的用法示例。
在下文中一共展示了Bitmap.DrawLine方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RenderPolygon
//.........这里部分代码省略.........
int x1;
bool x1YMin;
int x2 = int.MaxValue;
bool x2YMin = false;
///
/// add both x endpoints if the line is horizontal
///
if (lines[i].dy == 0)
{
x1 = lines[i].x1;
x1YMin = true;
x2 = lines[i].x2;
x2YMin = true;
if (x2 < 0) x2 = 0;
}
else
{
x1 = lines[i].cx;
x1YMin = lines[i].processedPts == 1;
}
// We don't need to process negative values of x
if (x1 < 0) x1 = 0;
int idx1 = -1;
int idx2 = x2 == int.MaxValue ? x2 : -1;
int offset = 0;
///
/// First we search for the indexes of x1 and x2 (if neccessary) and then we will insert the
/// items, by shifting the elements in the array
for (j = 0; j < n; j++)
{
int ix = (xPoints[j] & c_XValueMask);
bool isYMin = (xPoints[j] & c_YMinBit) != 0;
if (idx1 == -1)
{
///
/// Only add duplicate x values if the intersection produces up (^) or down (v) angles
/// as opposed to right (<) or left (>) angles.
///
if (ix == x1 && isYMin != x1YMin) { idx1 = int.MaxValue; }
else if (ix > x1 ) { idx1 = j + offset; offset++; }
}
if (idx2 == -1)
{
///
/// Only add duplicate x values if the intersection produces up (^) or down (v) angles
/// as opposed to right (<) or left (>) angles.
///
if (ix == x2 && isYMin != x2YMin) { idx2 = int.MaxValue; }
else if (ix > x2 ) { idx2 = j + offset; offset++; }
}
// don't break until we have found both indexes and then end of the list
if(idx1 != -1 && idx2 != -1 && xPoints[j] == int.MaxValue) break;
}
int idxMin = (idx1 < idx2 ? idx1 : idx2);
// Because we may have two values to insert, the index to the next item to be shifted
// can either be n-1 or n-2.
offset = (idx2 == int.MaxValue || idx1 == int.MaxValue ? 1 : 2);
// j is already one element past the last valid data item, so increase it by one if we are
// inserting two elements
j += (offset - 1);
// Make sure the index does not overflow
if (j >= xPoints.Length) j = xPoints.Length-1;
for (; j >= idxMin; j--)
{
if (j == idx1) { xPoints[j] = x1YMin ? x1 | c_YMinBit : x1; offset--; continue; }
if (j == idx2) { xPoints[j] = x2YMin ? x2 | c_YMinBit : x2; offset--; continue; }
if (j < offset) break;
xPoints[j] = xPoints[j - offset];
}
}
/// Finally draw the line segments to fill.
for (i = 0; i < xPoints.Length - 1; i += 2)
{
int ix1 = (xPoints[i ] & c_XValueMask);
int ix2 = (xPoints[i + 1] & c_XValueMask);
if ((ix1 == c_XValueMask) || (ix2 == c_XValueMask)) break;
bmp.DrawLine(Color, 1, ix1, y, ix2, y);
}
}
}
示例2: BitmapStressTest_StretchImage
public MFTestResults BitmapStressTest_StretchImage()
{
MFTestResults result = MFTestResults.Fail;
ArrayList bitmaps = new ArrayList();
Log.Comment("Allocate as many bitmaps as possible");
try
{
while (true)
{
Bitmap bmp = new Bitmap(width, height);
bmp.DrawLine(Color.White, 5, 0, 0, bmp.Width, bmp.Height);
bmp.DrawEllipse(Color.White, 4, 50, 50, 40, 11, Color.White, 0, 0, Color.Black, bmp.Width, bmp.Height, 5);
bitmaps.Add(bmp);
window.StretchImage(0, 0, bmp, width, height, 0xFF);
window.Flush();
}
}
catch (OutOfMemoryException e)
{
Log.Comment("Correctly threw exception: " + e.ToString());
result = MFTestResults.Pass;
}
finally
{
foreach (Bitmap b in bitmaps)
{
b.Dispose();
}
Debug.GC(true);
System.Threading.Thread.Sleep(500);
}
Log.Comment("Total Bitmap count = " + bitmaps.Count.ToString());
return result;
}
示例3: BitmapSuperStressTest_StretchImage
public MFTestResults BitmapSuperStressTest_StretchImage()
{
MFTestResults result = MFTestResults.Pass;
ArrayList bitmaps = new ArrayList();
Random random = new Random();
Log.Comment("Allocate as many bitmaps as possible");
for (int i = 0; i < 10; ++i)
{
try
{
while (true)
{
Bitmap bmp = new Bitmap(width, height);
bmp.DrawLine(Color.White, 5, 0, 0, bmp.Width, bmp.Height);
bmp.DrawEllipse(Color.White, 4, 50, 50, 40, 11, Color.White, 0, 0, Color.Black, bmp.Width, bmp.Height, 5);
bitmaps.Add(bmp);
window.StretchImage(0, 0, bmp, width, height, 0xFF);
window.Flush();
}
}
catch (OutOfMemoryException)
{
while (bitmaps.Count > 2)
bitmaps.RemoveAt(random.Next(bitmaps.Count));
}
catch (Exception e)
{
Log.Comment("Incorrect exception caught: " + e.ToString());
result = MFTestResults.Fail;
}
finally
{
foreach (Bitmap b in bitmaps)
{
b.Dispose();
}
}
Debug.GC(true);
System.Threading.Thread.Sleep(500);
}
Log.Comment("Total Bitmap count = " + bitmaps.Count.ToString());
return result;
}
示例4: LargeBitmapTest
public MFTestResults LargeBitmapTest()
{
MFTestResults result = MFTestResults.Fail;
ScreenSize[] pairs = new ScreenSize[] {
new ScreenSize( 160, 120 ), // QQVGA
new ScreenSize( 240, 160 ), // HQVGA
new ScreenSize( 320, 240 ), // QVGA
new ScreenSize( 480, 320 ), // HVGA
new ScreenSize( 640, 240 ), // HVGA
new ScreenSize( 864, 480 ), // FWVGA
new ScreenSize( 640, 480 ), // VGA
new ScreenSize( 800, 480 ), // WVGA
new ScreenSize( 848, 480 ), // WVGA
new ScreenSize( 854, 480 ), // WVGA
//new ScreenSize( 1024, 768 ), // XVGA
//new ScreenSize( 1152, 864 ), // XVGA+
//new ScreenSize( 1280, 1024 ), // SXGA
//new ScreenSize( 1400, 1050 ), // SXGA+
//new ScreenSize( 1600, 1200 ), // UXGA
};
Bitmap bmp = null;
try
{
foreach (ScreenSize p in pairs)
{
try
{
// the CLR's limit of allocation in the managed heap is sizeof(CLR_RT_HeapBlock) * (2^16) = 768432 bytes.
// To that one needs to subtract the size of an heap cluster (sizeof(CLR_RT_heapCluster)) and
// round to the number of heap blocks in the remaining amount, since the CLR allocated in heap blocks units.
// Thus some allocation (e.g. 800x600) must go in the unmanaged SimpleHeap if supported.
bmp = new Bitmap(p.width, p.height);
}
catch (OutOfMemoryException)
{
//SimpleHeap has no legitimate API to distinguish between no implementation
//or implemented but out-of-memory condition occurred. If OOM is thrown, assume
//it is because no SimpleHeap was provided.
// On the emulator though, we know it is implemented
if (Microsoft.SPOT.Hardware.SystemInfo.SystemID.SKU == 3)
{
return MFTestResults.Fail;
}
}
bmp.DrawLine(Color.White, 5, 0, 0, bmp.Width, bmp.Height);
bmp.DrawEllipse(Color.White, 4, 50, 50, 40, 11, Color.White, 0, 0, Color.Black, bmp.Width, bmp.Height, 5);
window.StretchImage(0, 0, bmp, width, height, 0xFF);
window.Flush();
bmp.Dispose(); bmp = null; // this is particlarly needed for the allocation in the non-managed heap
}
result = MFTestResults.Pass;
}
finally
{
if (bmp != null)
{
bmp.Dispose();
}
Debug.GC(true);
System.Threading.Thread.Sleep(500);
}
return result;
}