久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

將現(xiàn)有圖形轉(zhuǎn)換為位圖

Existing Graphics into Bitmap(將現(xiàn)有圖形轉(zhuǎn)換為位圖)
本文介紹了將現(xiàn)有圖形轉(zhuǎn)換為位圖的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我正在為交易軟件(C#、w??informs、.NET 3.5)編寫一個(gè)插件,我想在包含數(shù)據(jù)的面板(比如 ChartPanel)上繪制一個(gè)十字光標(biāo)畫畫可能很貴.到目前為止,我所做的是:

I'm writing a plugin for a trading software (C#, winforms, .NET 3.5) and I'd like to draw a crosshair cursor over a panel (let's say ChartPanel) which contains data that might be expensive to paint. What I've done so far is:

  1. 我在面板中添加了一個(gè) CursorControl
    • CursorControl 位于主繪圖面板上方,以便覆蓋整個(gè)區(qū)域
    • 它是 Enabled = false 以便所有輸入事件都傳遞給父級(jí)圖表面板
    • 實(shí)現(xiàn)了它的Paint方法,以便它在當(dāng)前鼠標(biāo)位置從上到下和從左到右繪制線條
  1. I added a CursorControl to the panel
    • this CursorControl is positioned over the main drawing panel so that it covers it's entire area
    • it's Enabled = false so that all input events are passed to the parent ChartPanel
    • it's Paint method is implemented so that it draws lines from top to bottom and from left to right at current mouse position
  • A) 調(diào)用 ChartPanel.Invalidate(),但正如我所說,底層數(shù)據(jù)的繪制可能很昂貴,這會(huì)導(dǎo)致每次移動(dòng)鼠標(biāo)時(shí)都重新繪制所有內(nèi)容,這是錯(cuò)誤的(但是這是我現(xiàn)在可以完成這項(xiàng)工作的唯一方法)
  • B) 調(diào)用 CursorControl.Invalidate() 并且在繪制光標(biāo)之前我會(huì)拍攝當(dāng)前繪制數(shù)據(jù)的快照并將其作為光標(biāo)的背景,每次光標(biāo)都會(huì)恢復(fù)需要重新粉刷……問題是……我不知道該怎么做.
  • A) Call ChartPanel.Invalidate(), but as I said, the underlying data may be expensive to paint and this would cause everything to redraw everytime I move a mouse, which is wrong (but it is the only way I can make this work now)
  • B) Call CursorControl.Invalidate() and before the cursor is drawn I would take a snapshot of currently drawn data and keep it as a background for the cursor that would be just restored everytime the cursor needs to be repainted ... the problem with this is ... I don't know how to do that.

2.B.意思是:

  • 將現(xiàn)有的 Graphics 對(duì)象轉(zhuǎn)換為 Bitmap(它(圖形)是通過 Paint 方法提供給我的,我必須在它上面作畫,所以我只是無法創(chuàng)建新的 Graphics 對(duì)象......也許我理解錯(cuò)了,但我是這么理解的)
  • 在繪制十字準(zhǔn)線之前,從位圖中恢復(fù)圖形內(nèi)容并重新繪制十字準(zhǔn)線
  • Turn existing Graphics object into Bitmap (it (the Graphics) is given to me through Paint method and I have to paint at it, so I just can't create a new Graphics object ... maybe I get it wrong, but that's the way I understand it)
  • before the crosshair is painted, restore the Graphics contents from the Bitmap and repaint the crosshair

我無法控制繪制昂貴數(shù)據(jù)的過程.我只能訪問我的 CursorControl 以及通過 API 調(diào)用的方法.

I can't control the process of painting the expensive data. I can just access my CursorControl and it's methods that are called through the API.

那么有沒有什么辦法可以把已有的Graphics內(nèi)容存入Bitmap中,以后再恢復(fù)呢?或者有什么更好的方法可以解決這個(gè)問題?

So is there any way to store existing Graphics contents into Bitmap and restore it later? Or is there any better way to solve this problem?

已解決:經(jīng)過數(shù)小時(shí)的反復(fù)試驗(yàn),我想出了一個(gè)可行的解決方案.我用的軟件有很多問題不能一概而論,但主要的原則是明確的:

RESOLVED: So after many hours of trial and error I came up with a working solution. There are many issues with the software I use that can't be discussed generally, but the main principles are clear:

  • 已經(jīng)繪制的現(xiàn)有圖形不能直接轉(zhuǎn)換為位圖,而是我必須使用@Gusman 的回答中首先提到的 panel.DrawToBitmap 方法.我知道,我想避免它,但最終我不得不接受,因?yàn)樗坪跏俏ㄒ坏姆椒?/li>
  • 我還想避免每一幀都重復(fù)繪制,所以第一個(gè)十字線繪制總是直接繪制到ChartPanel.在鼠標(biāo)移動(dòng)而不更改圖表圖像后,我通過 DrawToBitmap 進(jìn)行快照并按照所選答案中的描述進(jìn)行操作.
  • 控件必須是不透明的(未啟用透明背景),以便刷新它不會(huì)在其父控件上調(diào)用 Paint(這會(huì)導(dǎo)致整個(gè)圖表重新繪制)
  • existing Graphics with already painted stuff can't be converted to Bitmap directly, instead I had to use panel.DrawToBitmap method first mentioned in @Gusman's answer. I knew about it, I wanted to avoid it, but in the end I had to accept, because it seems to be the only way
  • also I wanted to avoid double drawing of every frame, so the first crosshair paint is always drawn directly to the ChartPanel. After the mouse moves without changing the chart image I take a snapshow through DrawToBitmap and proceed as described in chosen answer.
  • The control has to be Opaque (not enabled Transparent background) so that refreshing it doesn't call Paint on it's parent controls (which would cause the whole chart to repaint)

我仍然每隔幾秒左右就會(huì)偶爾出現(xiàn)閃爍,但我想我可以以某種方式解決這個(gè)問題.雖然我選擇了 Gusman 的答案,但我要感謝所有參與的人,因?yàn)槲沂褂昧似渌鸢钢刑岬降脑S多其他技巧,例如 Panel.BackgroundImage、使用 Plot() 方法而不是 Paint() 來鎖定圖像等.

I still experience occasional flicker every few seconds or so, but I guess I can figure that out somehow. Although I picked Gusman's answer, I would like to thank everyone involved, as I used many other tricks mentioned in other answers, like the Panel.BackgroundImage, use of Plot() method instead of Paint() to lock the image, etc.

推薦答案

為什么不將 ChartPanel 中的所有圖形克隆到 CursorControl 上?

Why don't you clone all the graphics in the ChartPanel over your CursorControl?

此處的所有代碼都必須放在 CursorControl 中.

All the code here must be placed inside your CursorControl.

首先,創(chuàng)建一個(gè)屬性,該屬性將保存對(duì)圖表的引用并與其繪制事件掛鉤,如下所示:

First, create a property which will hold a reference to the chart and hook to it's paint event, something like this:

ChartPanel panel;

public ChartPanel Panel
{ 
    get{ return panel; } 

    set{ 

         if(panel != null)
            panel.Paint -= CloneAspect;

         panel = value;

         panel.Paint += CloneAspect;
    }

}

現(xiàn)在定義 CloneAspect 函數(shù),該函數(shù)將在圖表面板中完成繪制操作時(shí)將控件的外觀呈現(xiàn)為位圖:

Now define the CloneAspect function which will render the control's appearance to a bitmap whenever a Paint opperation has been done in the Chart panel:

Bitmap aspect;

void CloneAspect(object sender, PaintEventArgs e)
{

    if(aspect == null || aspect.Width != panel.Width || aspect.Height != panel.Height)
    {

         if(aspect != null)
            aspect.Dispose();

         aspect = new Bitmap(panel.Width, panel.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);

    }

    panel.DrawToBitmap(aspect, new Rectangle(0,0, panel.Width, panel.Height);

}

然后在 OnPaint 重寫方法中執(zhí)行以下操作:

Then in the OnPaint overriden method do this:

public override void OnPaint(PaintEventArgs e)
{
    e.Graphics.DrawImage(aspect);

    //Now draw the cursor
    (...)
}

最后,無論您在何處創(chuàng)建圖表和自定義光標(biāo):

And finally wherever you create the chart and the customcursor you do:

CursorControl.Panel = ChartPanel;

瞧,您可以根據(jù)需要重新繪制多次,而無需重新計(jì)算圖表的內(nèi)容.

And voila, you can redraw as many times you need without recalculating the chart's content.

干杯.

這篇關(guān)于將現(xiàn)有圖形轉(zhuǎn)換為位圖的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Right-click on a Listbox in a Silverlight 4 app(右鍵單擊 Silverlight 4 應(yīng)用程序中的列表框)
WPF c# webbrowser scrolls over top menu(WPF c# webbrowser 在頂部菜單上滾動(dòng))
C# Console app - How do I make an interactive menu?(C# 控制臺(tái)應(yīng)用程序 - 如何制作交互式菜單?)
How to add an icon to System.Windows.Forms.MenuItem?(如何向 System.Windows.Forms.MenuItem 添加圖標(biāo)?)
How to avoid duplicate form creation in .NET Windows Forms?(如何避免在 .NET Windows Forms 中創(chuàng)建重復(fù)的表單?)
Building a database driven menu with ASP.NET, JQuery and Suckerfish(使用 ASP.NET、JQuery 和 Suckerfish 構(gòu)建數(shù)據(jù)庫驅(qū)動(dòng)的菜單)
主站蜘蛛池模板: 久久狠狠干 | 久久午夜视频 | 在线成人免费 | 好吊视频一区二区三区四区 | 在线观看av的网站 | 国产成人福利 | 簧片在线免费观看 | h片免费| 欧美一区二区在线观看 | 久久精品久久久久久久 | 谁有毛片网址 | 亚洲一区二区三区免费视频 | 香蕉视频一区 | 成人小视频在线 | 免费黄色小视频 | 成人福利网站 | 91在线看片 | 夫妻av | 四虎黄色影院 | 日韩欧美一级 | 久久人人爱| av中文天堂 | 97操碰| 一区二区福利视频 | 久久久三级 | 日韩小视频在线观看 | 黄色大片一级 | 日韩在线视频一区二区三区 | 激情五月婷婷 | 国产精品欧美激情 | 免费黄色一级 | 欧美视频在线一区 | 18精品爽国产白嫩精品 | 日韩专区在线观看 | av免费看网站 | 激情五月综合色婷婷一区二区 | 一区二区三区影院 | 懂色av一区二区夜夜嗨 | 蜜乳av懂色av粉嫩av | 日韩999 | a级片在线免费观看 |