本文整理汇总了C#中System.Drawing.Image.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# Image.Clone方法的具体用法?C# Image.Clone怎么用?C# Image.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Image
的用法示例。
在下文中一共展示了Image.Clone方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MainForm
public MainForm()
{
InitializeComponent();
m_CameraParameters = CameraParameters.Load(@"..\..\..\..\CalibrationFiles\MicrosoftCinema\Focus14\1280x720\MicrosoftCinemaFocus14_1280x720.txt");
m_RawImage = new Image<Bgr, byte>(@"..\..\..\..\CalibrationFiles\MicrosoftCinema\Focus14\1280x720\GroundProjectionCalibration.jpg");
this.CurrentImage = m_RawImage.Clone();
this.BirdsEyeImage = m_RawImage.Clone();
InitializeUndistortMap(m_RawImage);
Undistort(m_RawImage, this.CurrentImage);
this.ChessBoard = new ChessBoard(8, 10);
PointF[] foundCorners = CollectImageCorners();
DrawFoundCorners(this.CurrentImage, foundCorners);
// We pick four corners for perspective transform
PointF[] outerCorners = new PointF[4];
outerCorners[0] = foundCorners[0];
outerCorners[1] = foundCorners[this.ChessBoard.PatternSize.Width - 1];
outerCorners[2] = foundCorners[this.ChessBoard.PatternSize.Width * this.ChessBoard.PatternSize.Height - this.ChessBoard.PatternSize.Width];
outerCorners[3] = foundCorners[this.ChessBoard.PatternSize.Width * this.ChessBoard.PatternSize.Height - 1];
DrawOuterCorners(this.CurrentImage, outerCorners);
float side;
float bottom;
float centerX;
side = 25.0f;
bottom = 310.0f;
PointF[] physicalPointsForCalculation = new PointF[4];
physicalPointsForCalculation[0] = new PointF(-3 * side, bottom + 8 * side);
physicalPointsForCalculation[1] = new PointF(+3 * side, bottom + 8 * side);
physicalPointsForCalculation[2] = new PointF(-3 * side, bottom);
physicalPointsForCalculation[3] = new PointF(+3 * side, bottom);
m_BirdsEyeViewTransformationForCalculation = CameraCalibration.GetPerspectiveTransform(outerCorners, physicalPointsForCalculation);
HomographyMatrixSupport.Save(m_BirdsEyeViewTransformationForCalculation, "BirdsEyeViewTransformationForCalculation.txt");
side = 8f;
bottom = 700.0f;
centerX = (float)m_CameraParameters.Intrinsic.Cx;
PointF[] physicalPointsForUI = new PointF[4];
physicalPointsForUI[0] = new PointF(-3 * side + centerX, bottom - 8 * side);
physicalPointsForUI[1] = new PointF(+3 * side + centerX, bottom - 8 * side);
physicalPointsForUI[2] = new PointF(-3 * side + centerX, bottom);
physicalPointsForUI[3] = new PointF(+3 * side + centerX, bottom);
m_BirdsEyeViewTransformationForUI = CameraCalibration.GetPerspectiveTransform(outerCorners, physicalPointsForUI);
HomographyMatrixSupport.Save(m_BirdsEyeViewTransformationForUI, "BirdsEyeViewTransformationForUI.txt");
//m_BirdsEyeViewTransformationForCalculation.ProjectPoints(outerCorners);
CreateAndDrawBirdsEyeView();
}
示例2: DrawTools
/// <summary>
/// 初始化绘图工具
/// </summary>
/// <param name="g">绘图板</param>
/// <param name="c">绘图颜色</param>
/// <param name="img">初始画布</param>
public DrawTools(Graphics g, Color c, Image img)
{
DrawTools_Graphics = g;
drawColor = c;
p = new Pen(c, 1);
finishingImg = (Image)img.Clone();
orginalImg = (Image)img.Clone();
}
示例3: RLSA
//Implémentation de RLSA (j'ai rien compris mais ça marche) retourne le document structuré
public Image<Gray, byte> RLSA(Image<Gray, byte> tmpImg)
{
Image<Gray, byte> calcul = tmpImg.Clone();
Image<Gray, byte> vertical = RLSAV(calcul);
Image<Gray, byte> horizontal = RLSAH(calcul);
Image<Gray, byte> structure = tmpImg.Clone();
CvInvoke.BitwiseAnd(vertical, horizontal, structure);
return structure;
}
示例4: CropTransformation
public CropTransformation(Image sourceImage, Point point, Size size)
{
_disposed = false;
_sourceImage = sourceImage.Clone() as Image;
_point = point;
_size = size;
}
示例5: EditMapView
public EditMapView(string title, int fieldsize, int hitbox, Image image, MapCreatorView mapCreatorView)
{
InitializeComponent();
this.EveryNode = new BindingList<Node>();
this.title = title;
this.Fieldsize = fieldsize;
this.hitbox = hitbox;
this.Image = (Image)image.Clone();
this.MapCreatorView = mapCreatorView;
this.Text = String.Concat("Currently editing: ", title);
this.pictureBoxMapImage.Location = new Point(this.Size.Width, this.rButtonAddCarStartPosition.Location.Y);
// Grid
this.DrawGrid();
// Get all nodes
this.CalculateEveryNode();
this.listBoxEveryNode.DataSource = this.EveryNode;
this.listBoxEveryNode.ValueMember = "ListDisplay";
this.pictureBoxMapImage.Image = this.Image;
this.CalculateNewViewSize();
this.DrawUsedNodesFromList(this.MapCreatorView.CarStartPositions, Color.Red);
this.DrawUsedNodesFromList(this.MapCreatorView.RoundFinishedPositions, Color.Black);
this.DrawUsedNodesFromList(this.MapCreatorView.ForbiddenPositions, Color.Blue);
this.ActiveButton = "carStartPosition";
}
示例6: ResizeTransformation
public ResizeTransformation(Image sourceImage, int width, int height)
{
_disposed = false;
_sourceImage = sourceImage.Clone() as Image;
_width = width;
_height = height;
}
示例7: AddNextFrameToQueueForProcessing
//ADDS A CAPTURED FRAME TO A THREAD SAFE QUEUE FOR EASY ACESS WHEN THE FRAME IS PROCESSED BY MULTIPLE FRAMES
public bool AddNextFrameToQueueForProcessing()
{
using (current_frame = FramesManager.GetNextFrame(camera.camera_capture))
{
if (current_frame != null)
{
int width = Singleton.MAIN_WINDOW.GetControl(MainWindow.MainWindowControls.review_image_box).Width;
int height = Singleton.MAIN_WINDOW.GetControl(MainWindow.MainWindowControls.review_image_box).Height;
Size new_size = new Size(width, height);
Singleton.REVIEW_FRAMES_TO_BE_PROCESSED.Enqueue(FramesManager.ResizeColoredImage(current_frame.Clone(), new_size));
return true;
}
//FRAME IS NULL
//MEANING END OF FILE IS REACHED
else
{
//ADD BLACK FRAME TO DATASTORE AND TERMINATE THREAD
//ALSO SIGNAL TO OTHERS THAT THIS THREAD IS DONE
WORK_DONE = true;
running = false;
Debug.WriteLine("Terminating video from file");
return false;
}
}
}
示例8: ImageEditor
/// <summary>
/// Initializes a new instance of <see cref="T:Dataweb.NShape.WinFormsUI.ImageEditor" />.
/// </summary>
public ImageEditor(Image image, string path)
: this() {
if (image == null) throw new ArgumentNullException("image");
if (path == null) throw new ArgumentNullException("name");
resultImage.Image = (Image)image.Clone();
resultImage.Name = path;
}
示例9: ToGreyScale
public static Image ToGreyScale(Image Source)
{
Bitmap grayscale = (Bitmap)Source.Clone();
Rectangle bounds = new Rectangle(0, 0, grayscale.Width, grayscale.Height);
ColorMatrix colorMatrix = new ColorMatrix();
int mX = 0;
int mY = 0;
for (mX = 0; mX <= 2; mX++)
{
for (mY = 0; mY <= 2; mY++)
{
colorMatrix[mX, mY] = 0.333333F;
}
}
ImageAttributes imgAttr = new System.Drawing.Imaging.ImageAttributes();
imgAttr.SetColorMatrix(colorMatrix);
System.Drawing.Graphics graphics = Graphics.FromImage(grayscale);
try
{
graphics.DrawImage(grayscale, bounds, 0, 0, grayscale.Width, grayscale.Height, System.Drawing.GraphicsUnit.Pixel, imgAttr);
}
finally
{
graphics.Dispose();
}
return grayscale;
}
示例10: ChangeAllColorTo
public static Bitmap ChangeAllColorTo(Image img, Color c)
{
if (img == null)
return null;
if (img.PixelFormat.HasFlag(PixelFormat.Indexed))
return (Bitmap)img;
Bitmap bmp = (Bitmap)img.Clone();
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
IntPtr ptr = bmpData.Scan0;
int len = bmp.Width * bmp.Height * 4;
byte[] data = new byte[len];
Marshal.Copy(ptr, data, 0, len);
byte R = c.R;
byte G = c.G;
byte B = c.B;
for (int i = 0; i < data.Length; i += 4)
if (data[i + 3] != 0)
{
data[i + 0] = B;
data[i + 1] = G;
data[i + 2] = R;
}
Marshal.Copy(data, 0, ptr, len);
bmp.UnlockBits(bmpData);
return bmp;
}
示例11: TakeScreenshot
/// <summary>
/// Most of the time it just returns a black screen, this is because the game is rendering straight to the
/// graphics card using directx and bypassing whatever windows usually uses for PrintWindow
/// AFAIK directx screenshots only work if the window is currently visible (not overlaid by the bot itself)
/// </summary>
/// <returns></returns>
public Image<Bgr, byte> TakeScreenshot()
{
Bitmap frame = new Bitmap(1024, 768);
using (Graphics g = Graphics.FromImage(frame))
{
IntPtr deviceContextHandle = g.GetHdc();
PrintWindow(GetGameWindowHandle(), deviceContextHandle, 1);
g.ReleaseHdc();
}
//we have the bitmap now
//turn it into an Image for emgu
BitmapData bmpData = frame.LockBits(new Rectangle(0, 0, frame.Width, frame.Height), ImageLockMode.ReadWrite,
PixelFormat.Format24bppRgb);
Image<Bgr, byte> tempImage = new Image<Bgr, byte>(frame.Width, frame.Height, bmpData.Stride, bmpData.Scan0);
//to prevent any corrupted memory errors that crop up for some reason
Image<Bgr, byte> image = tempImage.Clone();
frame.UnlockBits(bmpData);
//dispose all unused image data to prevent memory leaks
frame.Dispose();
tempImage.Dispose();
image.Save("screenshot.png");
return image;
}
示例12: CombineImage
/// <summary>
/// 合并图像
/// </summary>
/// <param name="imageBackground"></param>
/// <param name="imageForeground"></param>
/// <param name="alignment"></param>
/// <returns></returns>
public static Image CombineImage(Image imageBackground, Image imageForeground, ContentAlignment alignment)
{
Image imageBk = imageBackground.Clone() as Image;
Graphics g = Graphics.FromImage(imageBk);
Point point;
switch (alignment)
{
case ContentAlignment.TopLeft:
point = new Point(0, 0);
break;
case ContentAlignment.TopRight:
point = new Point(imageBackground.Width - imageForeground.Width, 0);
break;
case ContentAlignment.BottomLeft:
point = new Point(0, imageBackground.Height - imageForeground.Height);
break;
case ContentAlignment.BottomRight:
point = new Point(imageBackground.Width - imageForeground.Width, imageBackground.Height - imageForeground.Height);
break;
case ContentAlignment.TopCenter:
point = new Point(imageBackground.Width / 2 - imageForeground.Width / 2, 0);
break;
case ContentAlignment.BottomCenter:
point = new Point(imageBackground.Width / 2 - imageForeground.Width / 2, imageBackground.Height - imageForeground.Height);
break;
default:
throw new NotSupportedException("Not supported alignment");
}
g.DrawImage(imageForeground, point);
return imageBk;
}
示例13: HandlePoint
public bool HandlePoint(Point point, System.Drawing.Graphics graphics, Image image)
{
if (IsNowPartitionDrawing)
{
if (!isPartitionExists)
{
isPartitionExists = true;
LastBitmap = image.Clone() as Bitmap;
}
if (!isBeginPointSet)
{
partitionBegin.X = point.X;
partitionBegin.Y = point.Y;
isBeginPointSet = true;
}
else
{
partitionEnd.X = point.X;
partitionEnd.Y = point.Y;
graphics.DrawLine(new Pen(partitionColor), partitionBegin, partitionEnd);
isBeginPointSet = false;
return true;
}
}
return false;
}
示例14: Watermark
public override Image Watermark(Image img)
{
img = (Image)img.Clone();
string text = (string)ConfigurationControl.Parameters["Text"];
Font font = (Font)ConfigurationControl.Parameters["Font"];
Color color = (Color)ConfigurationControl.Parameters["Color"];
ContentAlignment align = (ContentAlignment)ConfigurationControl.Parameters["Align"];
int offsetX = (int)ConfigurationControl.Parameters["OffsetX"];
int offsetY = (int)ConfigurationControl.Parameters["OffsetY"];
int trans = (int)ConfigurationControl.Parameters["Transparency"];
using (Graphics g = Graphics.FromImage(img))
{
int x, y;
Size size = g.MeasureString(text, font).ToSize();
// 计算文本位置
CaculateLocation(img.Size, size, align, offsetX, offsetY, out x, out y);
// 计算透明度 0 - 255 之间
int o = (int)((trans / 100.00) * 255);
// 创建具有透明度的画刷
Brush b = new SolidBrush(Color.FromArgb(o, color));
// 写水印文字
g.DrawString(text, font, b, new PointF(x, y));
return img;
}
}
示例15: AntiAliasing
/// <summary>
/// Apply an anti-aliasing algorithm on a Bitmap object
/// </summary>
/// <param name="_input">A Bitmap to anti-alias</param>
/// <returns>The anti-aliased Bitmap</returns>
public static Bitmap AntiAliasing(Bitmap _input)
{
Image<Bgra, Byte> input;
Image<Bgra, Byte> outputGaussian;
Image<Bgra, Byte> outputGaussianResized;
Image<Bgra, Byte> outputThreshold;
Image<Bgra, Byte> outputThresholdResized;
// Image loading
input = new Image<Bgra, Byte>(_input);
// Gaussian filter
outputGaussian = input.Clone();
for (int i = 1; i < 10; i = i + 2)
{
CvInvoke.cvSmooth(input, outputGaussian, SMOOTH_TYPE.CV_GAUSSIAN, i, i, 0, 0);
}
// Resize the image after the Gaussian filter (2 times bigger)
outputGaussianResized = new Image<Bgra, Byte>(outputGaussian.Cols * 2, outputGaussian.Rows * 2);
CvInvoke.cvResize(outputGaussian, outputGaussianResized, INTER.CV_INTER_CUBIC);
// Threshold
outputThreshold = outputGaussianResized.Clone();
CvInvoke.cvThreshold(outputGaussianResized, outputThreshold, 127, 255, THRESH.CV_THRESH_BINARY);
// Resize the image after the threshold (2 times smaller)
outputThresholdResized = new Image<Bgra, Byte>(outputThreshold.Cols / 2, outputThreshold.Rows / 2);
CvInvoke.cvResize(outputThreshold, outputThresholdResized, INTER.CV_INTER_CUBIC);
// Return the processed image
return outputThresholdResized.Bitmap;
}