Click here to Skip to main content
15,911,762 members
Home / Discussions / Graphics
   

Graphics

 
GeneralRe: "warp mode image transformation" in photoshop Pin
El Corazon15-Apr-08 6:02
El Corazon15-Apr-08 6:02 
GeneralRe: "warp mode image transformation" in photoshop Pin
Dan16-Apr-08 13:37
Dan16-Apr-08 13:37 
GeneralRe: "warp mode image transformation" in photoshop Pin
dapa17-Apr-08 2:17
dapa17-Apr-08 2:17 
GeneralAlgorithm to divide image into rectangulars of the same color [modified] Pin
xax14-Apr-08 5:37
xax14-Apr-08 5:37 
GeneralRe: Algorithm to divide image into rectangulars of the same color Pin
Luc Pattyn14-Apr-08 5:54
sitebuilderLuc Pattyn14-Apr-08 5:54 
GeneralRe: Algorithm to divide image into rectangulars of the same color Pin
xax15-Apr-08 12:43
xax15-Apr-08 12:43 
GeneralRe: Algorithm to divide image into rectangulars of the same colo Pin
Luc Pattyn15-Apr-08 13:10
sitebuilderLuc Pattyn15-Apr-08 13:10 
GeneralProcessor Intensive Programming [modified] Pin
Reelix14-Apr-08 1:52
Reelix14-Apr-08 1:52 
My friend and I were having an argument about the drawing speed of GDI+. First he presented the flicker problem, but I fixed that with

SetStyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);

then, after awhile, he presented the following:



<br />
using System;<br />
using System.Drawing;<br />
using System.Drawing.Imaging;<br />
using System.Runtime.InteropServices;<br />
using System.Windows.Forms;<br />
<br />
namespace SlowGdi {<br />
	public partial class SlowGdiForm : Form {<br />
<br />
		private Random RandomSource = new Random();<br />
<br />
		private int[] RandomPixels = new int[512 * 512];<br />
        <br />
		private Bitmap RandomBitmap = new Bitmap(512, 512);<br />
<br />
		public SlowGdiForm()<br />
        {<br />
			InitializeComponent();<br />
            this.Disposed += (sender, e) => this.RandomBitmap.Dispose();<br />
			Application.Idle += (sender, e) => this.Invalidate();<br />
		}<br />
<br />
        private void SlowGdiForm_Paint(object sender, PaintEventArgs e)<br />
        {<br />
            for (int i = 0; i < RandomPixels.Length; i++) {<br />
				this.RandomPixels[i] = this.RandomSource.Next();<br />
			}<br />
			var Locked = this.RandomBitmap.LockBits(new Rectangle(0, 0, 512, 512), ImageLockMode.WriteOnly, PixelFormat.Format32bppRgb);<br />
            Marshal.Copy(this.RandomPixels, 0, Locked.Scan0, 512 * 512);<br />
			this.RandomBitmap.UnlockBits(Locked);<br />
            e.Graphics.DrawImage(this.RandomBitmap, 0, 0, 512, 512);//this.ClientSize.Width, this.ClientSize.Height);<br />
        }<br />
<br />
        private void SlowGdiForm_Load(object sender, EventArgs e)<br />
        {<br />
            SetStyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);<br />
        }<br />
	}<br />
}<br />
<br />



This looks all cool, but do a quick Ctrl+Alt+Delete, and notice the 100% Processor Usage (50% on Dual Core)


Anyone have any idea on how to optimise the code to NOT annihilate the processor?

Thanks Smile | :)

- Reelix

P.S: Thread.Sleep(1); helps abit, but not all that much...

P.P.S: Apparently it works perfectly on Vista...

modified on Monday, April 14, 2008 7:58 AM

GeneralRe: Processor Intensive Programming Pin
El Corazon14-Apr-08 4:33
El Corazon14-Apr-08 4:33 
Generalwant suggestion Pin
bharathn8712-Apr-08 8:46
bharathn8712-Apr-08 8:46 
GeneralShading Pin
meister_skypie6-Apr-08 1:13
meister_skypie6-Apr-08 1:13 
GeneralRe: Shading Pin
Tim Craig6-Apr-08 16:05
Tim Craig6-Apr-08 16:05 
GeneralRe: Shading Pin
El Corazon8-Apr-08 7:20
El Corazon8-Apr-08 7:20 
QuestionPartially redraw Image Pin
invader824-Apr-08 3:31
invader824-Apr-08 3:31 
GeneralRe: Partially redraw Image Pin
Luc Pattyn4-Apr-08 3:41
sitebuilderLuc Pattyn4-Apr-08 3:41 
GeneralRe: Partially redraw Image Pin
invader824-Apr-08 3:50
invader824-Apr-08 3:50 
GeneralGDI+ - Disposing Pin
molcaobarman30-Mar-08 7:14
molcaobarman30-Mar-08 7:14 
GeneralRe: GDI+ - Disposing Pin
Mark Salsbery30-Mar-08 9:40
Mark Salsbery30-Mar-08 9:40 
GeneralRe: GDI+ - Disposing Pin
Luc Pattyn30-Mar-08 10:24
sitebuilderLuc Pattyn30-Mar-08 10:24 
GeneralRe: GDI+ - Disposing Pin
molcaobarman1-Apr-08 21:23
molcaobarman1-Apr-08 21:23 
GeneralRe: GDI+ - Disposing Pin
Luc Pattyn1-Apr-08 23:38
sitebuilderLuc Pattyn1-Apr-08 23:38 
GeneralRe: GDI+ - Disposing Pin
molcaobarman2-Apr-08 0:16
molcaobarman2-Apr-08 0:16 
QuestionSemi Transparent UserControl Pin
maxatlis30-Mar-08 0:04
maxatlis30-Mar-08 0:04 
GeneralRe: Semi Transparent UserControl [modified] Pin
Rob Smiley18-Apr-08 9:48
Rob Smiley18-Apr-08 9:48 
GeneralFlashy GDI+ Pin
Reelix28-Mar-08 0:58
Reelix28-Mar-08 0:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.