一个图片框中的多个图形图像 [英] Multiple graphics images in one picturebox

查看:153
本文介绍了一个图片框中的多个图形图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何帮助都表示赞赏。



我要创建一个应用程序,我可以在图片框的某些位置添加多个图像(来自png文件)在运行时。



我理解如何创建一个图形对象,这个图形显示在图片框中。



什么如果我想添加一个图像,然后放置另一个相同但旋转45度,然后另一个旋转一点等等...所有在同一个图片框上,并在我点击的位置,这是最好的方法。 br />


我是否使用一个'主'图形对象,这是图片框所显示的。



然后当我添加一个新的旋转图像时,我创建一个包含图像的临时图形对象,对该对象进行旋转...然后以某种方式将其添加到主图形对象中......然后显示在图片框中。 br />


有时我可能想要删除其中一个添加的图像并添加另一个图像。



任意帮助会很棒,

谢谢,西蒙。



我尝试了什么:



我尝试了很多不同的方法,但它不能正常工作。

Hi, Any help is appreciated.

I what to make an application where i can add multiple images (from a png file) in certain positions on a picturebox at runtime.

I understand how to create a graphics object and this graphic is displayed in the picturebox.

What is the best way to do this if i want to add one image then place another one of the same but rotated 45 degrees, then another rotated a bit more etc... all on the same picturebox, and in the position i click.

Do i use one 'master' graphics object which is what the picture box is showing.

Then when i add a new rotated image, i create a temp graphics object containing the image, do the rotate on that object.. and then somehow add this to the 'master' graphics object.. which is then displayed in the picture box.

At times i may want to remove one of the images added and add a different one.

Any help would be great,
Thanks, Simon.

What I have tried:

I have tried lots of different ways, but it doesn't work as i want.

推荐答案

根本没有意义。只是不要使用 PictureBox 控制,就是这样。这不是一个图像。



我很难理解为什么这么多的查询者被这种纯粹的冗余控制所困惑。它的唯一目的是减少做最简单的家务所需的工作量,显示一个静态图像。没有这种控制,任何人都可以直接做到。如果你想要一些更复杂的东西,控制变得麻烦,而不是帮助。



请看我过去的答案:

< a href =http://www.codeproject.com/Answers/352618/Append-a-picture-within-picturebox#answer1>在图片框中附加图片,

< a href =http://www.codeproject.com/Answers/318796/draw-a-rectangle-in-Csharp#answer1>在C#中绘制一个矩形,

< a href =http://www.codeproject.com/Answers/194885/How-do-I-clear-a-panel-from-old-drawing#answer2>如何从旧图纸中清除面板。



怎么办?上面的答案已经解释过:您创建自己的自定义控件并覆盖 OnPaint 或处理事件 Paint 。或者,您可以使用 Panel 之类的控件,甚至 Form 。在该方法或处理程序方法中,您可以呈现所需内容以及所需内容;其中包括渲染一些图像。



有关渲染的更多细节,请参阅我过去的答案:

什么样的俏皮方法是Paint? (DataGridViewImageCell.Paint(...))

在面板上捕捉绘图

在mdi子表单之间绘制线条



-SA
It makes no sense at all. Just don't use PictureBox control at all, that's it. It is not an image.

It's hard for me to understand why so many inquirers have been confused by this purely redundant control. Its sole purpose is to reduce amount of work needed to do simplest chores, showing a single static image. Anyone could do it directly, without this control. If you want anything a bit more complicated, the controls becomes a hassle, instead of help.

Please see my past answers:
Append a picture within picturebox,
draw a rectangle in C#,
How do I clear a panel from old drawing.

What to do? The answers reference above already explained that: you create your own custom control and override OnPaint or handle the event Paint. Alternatively, you can use a control like Panel, or even Form. In that method or a handler method, you render what you want and how you want; which includes rendering some images.

For further detail in rendering, please see my past answers:
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...)),
capture the drawing on a panel,
Drawing Lines between mdi child forms.

—SA


Simon问:

对不起......这有点高于我...你能快点做吗?例?真的很感激。此致,

Simon

Hi, Sorry... this is a bit above me… Are you able to do a quick example? It would be really appreciated. Best regards,
Simon

这是一个与图形交互行为相关的单独问题,以响应某些输入事件。我已经在解决方案1中引用过去的答案中描述了原理。



解决方案的架构可能类似于

This is a separate question related to the interactive behavior of graphics, in response to some input event. I already described the principle in my past answers referenced in Solution 1.

The schema of the solution may look something like

using System.Windows.Forms;
using System.Drawing;

//...

class MyControl : Control {

   static readonly double Increment = System.Math.PI * 5;
   
   double RotationAngle;

   protected override void OnMouseDown(MouseEventArgs e) {
       RotationAngle += Increment;
       Invalidate();
   }

   protected override void OnPaint(PaintEventArgs e) {
       // draw something with e.Graphics;
       var matrix = new System.Drawing.Drawing2D.Matrix();
       // decide around what point to rotate the way you want:
       PointF centerOfRotation = new System.Drawing.PointF(/* calculate it... */);
       matrix.Rotate(RotationAngle, centerOfRotation);
       e.Graphics.Transform = matrix;
       // draw something else...
       // optionally:
       e.Graphics.ResetTransform();
       // draw something else...
   }

}



很抱歉显示C#代码,而不是VB.NET;我只是不想浪费时间。您可以自己手动或使用许多可用工具轻松将其转换为VB.NET。你只需要了解原理。



你可以添加很多细节:限制你响应鼠标点击的区域,根据一些因素制作增量值,使控件的客户区域内的某个区域或矩形无效,依此类推。



-SA


这篇关于一个图片框中的多个图形图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆