图片在C#中的幻灯片显示文本 [英] Text for image slideshow in c#

查看:125
本文介绍了图片在C#中的幻灯片显示文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,我正在做一个项目,因为我每个图像都有一定的图像和文本文件.现在我想使用c#.net进行幻灯片放映,我已经成功完成了,现在我想向每个人显示特定的文本.图像作为脚注.

Hi Friends i am doing a project in that i have certain images and text files for every image.Now i want to show slide show using c#.net and i completed that successfully, now i want to show that particular text to every image as footnote. How to do it?

推荐答案

使用c#.net进行幻灯片放映,我成功完成了
在每张图片上显示特定的文字
由于您已经完成了幻灯片放映,这意味着您的图像将绑定到图像查看器,并且每次单击更改时,它就会在查看器中显示一个新图像.
在相同的更改事件中,更改文本和图像.您需要做的就是在图像查看器下方添加一个标签(可能是一个图片框).
与图像一样,获取文本,并对文本执行与对图像相同的操作.

试试吧,与您已经完成的工作相比,这非常简单.
show slide show using c#.net and i completed that successfully
show that particular text to every image
Since, you have already done the slide show, this means you image is getting bind to the image viewer and on every change click, it has a new image in the viewer.
In the same change event, change the text along with the image. All you need is to add a label below image viewer (a picture box probably).
Just with image, get the text along and do the same thing with text as you have done with image.

Try, it''s pretty simple compared to what you have already done.


创建一个包含要显示的对象和要显示的持续时间的元素队列.您可以使用虚拟Draw方法创建一个以上具有通用基类的类,并使基类成为队列的元素.使用通用类System.Collections.Generic.Queue.

创建一个线程并将队列输入到该线程.线程应逐元素读取队列元素,进行显示,并使用System.Threading.Thread.Sleep在每个帧(队列元素)中指定的一定时间.

在这一部分中,我必须假设您正在使用System.Windows.Forms(对于WPF,这部分是微不足道的).您的表单需要一个控件来呈现图像和文本.对于文本,可以使用标签或状态栏.它们将自动呈现.对于图形,请使用某些控件(甚至面板)并使用Paint事件进行渲染.事件的处理程序应使用队列元素类型的变量,将其称为CurrentFrame.线程只分配CurrectFrame,然后窗体读取它.因为这是一个共享内存区域,所以不要忘记在两个线程中都使用lock访问它. UI和非UI(让我们调用第二个方案线程).调用Control.Invalidate的结果将重新渲染面板的框架.因此,线程通过写入变量CurrectFrame来更改框架并使之无效.

最后,您的方案线程是非UI线程;因此它永远不能调用任何UI方法和属性.相反,它应该使用委托和System.Windows.Forms.ControlSystem.Threading.Dispatcher的方法BeginInvokeInvoke(在您的应用程序中首选)(同样适用于WPF).有关调用如何工作的详细信息,请参见:
Control.Invoke()与Control.BeginInvoke() [ ^ ]
Treeview Scanner和MD5的问题 [如何在vb.net中获取一个keydown事件以在不同的线程上运行 [如何将ref参数传递给线程 [ ^ ].

基本上就是这样.该应用程序如果相当简单.

—SA
Create a queue of the elements containing an object to display and duration to show. You can create more than one class with common base class with virtual Draw method and make the base class the element of the queue. Use the generic class System.Collections.Generic.Queue.

Create a thread and feed the queue to it. The thread should read the queue element by element, display it and use System.Threading.Thread.Sleep some amount of time specified in each frame (queue element).

In this part, I have to assume you''re using System.Windows.Forms (for WPF, this part is trivial). Your form needs a control to render the image and text. For text, you can use a label or status bar; they will be rendered automatically. For graphics, use some control (even panel) and do rendering using Paint event. The handler of the event should use a variable of the queue element type, call it CurrentFrame. The thread simply assigns CurrectFrame and the form reads it. As this is a shared memory area, don''t forget accessing it using lock from both threads; UI and non-UI (let''s call the second one Scenario thread). The panel''s frame will be re-rendered as a result of the call to Control.Invalidate. So, the thread change the frame through writing to the variable CurrectFrame and invalidate.

Finally, your scenario thread is non-UI thread; so it can never call any UI methods and properties. Instead, it should use delegates and the method BeginInvoke or Invoke (preferred in your application) of System.Windows.Forms.Control or System.Threading.Dispatcher (works for WPF as well). For details on how Invocation works, see:
Control.Invoke() vs. Control.BeginInvoke()[^]
Problem with Treeview Scanner And MD5[^]

More on threading: How to get a keydown event to operate on a different thread in vb.net[^].
For thread creation and passing parameters, I recommend using the thread wrapper, see my code here:
How to pass ref parameter to the thread[^].

That''s it, basically. The application if fairly simple.

—SA


这篇关于图片在C#中的幻灯片显示文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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