473,320 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

gdi+ question

ZQ
Hi everyone!

I have a question about GDI+.

float deltaY = 0;

// the onPaint handler of my control
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.TranslateTransform(0, deltaY);
GenerateGraphics(e.Graphics);
}

In an OnClick event, I change the value of deltaY, and invalidate the
control.
Everything works fine - the graphics is then moved upwards or downwards -
depending
what the deltaY is set to, but it's very slow.

So I figured I should use BufferedGraphics and do something like this:

BufferedGraphics buff;
float deltaY = 0;

....somewhere in the code...
InitializeBufferedGraphics(buff);

....elsewhere in the code...
GenerateGraphics(buff.Graphics);
// this draws strings and rectangles and stuff on the buffered graphics
// this happens only when graphics needs to be changed, and not in the
OnPaint handler like it used
// to be earlier

// the onPaint handler of my control
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.TranslateTransform(0, deltaY);
buff.Render(e.Graphics);
}

However, the TranslateTransform has absolutely no effect on buff.Render. -
the graphics rendered
from bufferedGraphics is not moved anywhere.

Is there a way to render the BufferedGraphics object over the OnPaint's
Graphics object, but translated?
Mar 24 '06 #1
2 2625
see inline.

ZQ wrote:
Hi everyone!

I have a question about GDI+.

float deltaY = 0;

// the onPaint handler of my control
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.TranslateTransform(0, deltaY);
GenerateGraphics(e.Graphics);
}

In an OnClick event, I change the value of deltaY, and invalidate the
control.
Everything works fine - the graphics is then moved upwards or downwards -
depending
what the deltaY is set to, but it's very slow.

So I figured I should use BufferedGraphics and do something like this:

BufferedGraphics buff;
float deltaY = 0;

...somewhere in the code...
InitializeBufferedGraphics(buff);

...elsewhere in the code...
GenerateGraphics(buff.Graphics);
// this draws strings and rectangles and stuff on the buffered graphics
// this happens only when graphics needs to be changed, and not in the
OnPaint handler like it used
// to be earlier

// the onPaint handler of my control
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.TranslateTransform(0, deltaY); [ you probably need to the transfer on the BufferedGraphics
buff.Graphics.TranslateTransform(0, deltaY);
buff.Render(e.Graphics);
}

However, the TranslateTransform has absolutely no effect on buff.Render. -
the graphics rendered
from bufferedGraphics is not moved anywhere.

Is there a way to render the BufferedGraphics object over the OnPaint's
Graphics object, but translated?

Mar 24 '06 #2
ZQ
Thanks for your response!

I considered that, and buff.Graphics.TranslateTransform(0, deltaY) has no
effect whatsoever.
TranslateTransform does it's transformations only on things that are drawn
AFTER it is called.

In this case:
1. a lot of things are drawn to buff.Graphics at time X
2. inside OnPaint(), buff.Graphics is rendered to the e.Graphics (everything
shows up on screen ok)
3. when user clicks a button only deltaY changes, nothing new is drawn on
buff.Graphics -- therefore, if I call the
buff.Graphics.TranslateTransform(0, deltaY) now, it won't apply to anything
because nothing is drawn after that
4. i call this.Invlidate() to refresh the control and display the translated
drawings
5. inside OnPaint(), buff.Graphics is rendered to the e.Graphics (it is
supposed to be on a new location, but it seems impossible)

I expected it to be normal that e.Graphics.translateTransform (...) would
affect everything that is rendered to e.Graphics from bufferedGraphics, but
that doesn't seem to be right.

It seems to me all I can do is optimize the GenerateGraphics method.
"Jianwei Sun" <js***********@gmail.com> wrote in message
news:eA**************@tk2msftngp13.phx.gbl...
see inline.

ZQ wrote:
Hi everyone!

I have a question about GDI+.

float deltaY = 0;

// the onPaint handler of my control
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.TranslateTransform(0, deltaY);
GenerateGraphics(e.Graphics);
}

In an OnClick event, I change the value of deltaY, and invalidate the
control.
Everything works fine - the graphics is then moved upwards or downwards -
depending
what the deltaY is set to, but it's very slow.

So I figured I should use BufferedGraphics and do something like this:

BufferedGraphics buff;
float deltaY = 0;

...somewhere in the code...
InitializeBufferedGraphics(buff);

...elsewhere in the code...
GenerateGraphics(buff.Graphics);
// this draws strings and rectangles and stuff on the buffered graphics
// this happens only when graphics needs to be changed, and not in the
OnPaint handler like it used
// to be earlier

// the onPaint handler of my control
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.TranslateTransform(0, deltaY);

[ you probably need to the transfer on the BufferedGraphics
buff.Graphics.TranslateTransform(0, deltaY);
buff.Render(e.Graphics);
}

However, the TranslateTransform has absolutely no effect on
buff.Render. - the graphics rendered
from bufferedGraphics is not moved anywhere.

Is there a way to render the BufferedGraphics object over the OnPaint's
Graphics object, but translated?


Mar 24 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Charles Law | last post by:
If I draw a rectangle, 6 inches by 2 inches, on a user control with a PageUnit of Inches, I get a rectangle of 7 by 2.2 inches. Is this what people would expect? I would have hoped that it was at...
1
by: pei_world | last post by:
Hi there, I have a problem about how to keep my draw graphics stay on my control unless I delete them. that means how to resist my graphics. also how to partially remove some graphics from my...
1
by: David Sobey | last post by:
Hi I'm making a custom component using GDI+, a calendar grid thingy. I paint the grid and numbers in my overrided OnPaint. However, when i go to paint other things at other times in other...
8
by: Brian Basquille | last post by:
Hello all, Just a quick GDI+ related question for you all. I've three ellipses being drawn in my game. I'm trying to smoothen the edges of them out using anti-aliasing. Why is it that my puck...
7
by: news | last post by:
This may be a stupid question, but if I don't ask I'll never know ;) Ok, here it goes.... I am writing an application that renders an image in one picturebox and a graph in another. The image...
7
by: | last post by:
We create VC++ programs that does some GDI drawing functionality. I discovered GDI+ and this seems to be a big step forward, and appears to be standard available in Windows XP and Windows Server...
5
by: jack | last post by:
In using GDI+ drawstring, if the string to be drawn is in rtf format, how do I make GDI+ to recognize the rtf attributes. In other words, how do I draw one string in GDI+ , within which the...
2
by: SStory | last post by:
Question #1) If I do Image.Save with the same filepath that I got the image from, it bombs with "A generic error occurred in GDI+" Any ideas? I prompt the user before overwriting, but if they...
7
by: Marcin Rzeznicki | last post by:
Hello, Do you think it is legitimate practice to mix GDI+ and GDI calls (via Get/ReleaseHDC()) in paint event of a control? I've heard there is possibility of performance loss while "locking"...
1
by: Chris Dunaway | last post by:
When working with GDI+, calling the CreateGraphics method to draw on a control has normally been frowned upon and it is always emphasized to dispose of pens and brushes and other GDI objects lest...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.