drawing support over an image in .net compact framework

  • Thread starter Thread starter Abhishek
  • Start date Start date
A

Abhishek

Hello everyone,

I am a newbee & this is my first post so my questions might be naive but I
hope I get helped because I am just started for dotnet for my research.

My objective is to display a jpg image and then overlay on it a curve or a
rectangle that the user can select and modify. I made a panel control, used
DrawImage, and then added a paint event handler for the panel control in
which I drew both the image (using DrawImage ofcourse) and then the
rectangle (using DrawRectangle). I attached a click event with the panel
control which hit-tests the co-ordinates, changes the co-ordinates of the
rectangle drawn, and calls this.panel1.Invalidate(). This works but I am not
happy with the performance considering I will be doing this for a pocket pc.
I need suggestions. My basic problem is that I don't want the image to be
redrawn again and again as the user selects the rectangle and moves it
around.

I don't know if this is something to do with .net compact, that I had a
problem creating a GraphicsObject, it just does not compile. Is it even
supported?

Also from an architecture perspective I need a suggestion, I understand
drawing lines and curves, overlaying them over an image, allowing user to
modify them, must be a common requirement. I want to know the right
architecture to do it. I want to provide a functionality similar to there is
MS paint and the likes. Also please note when I mention rectangle it is just
to simplify my problem the curve that I wish to draw and allow the user to
modify would have a complex equations and set of points being calculated
from that equation which would also have set of control points which the
user can move and the curve will change its shape.

Pls help me. looking forward to replies! thanks in anticipation.

Abhishek
 
Keep tha background image in a bitmap, draw your new stuff onto that bitmap,
then blit the entire thing to your control. Be sure to override
OnBackgroundPaint to get better perf.

-Chris
 
Thanks for your reply. My background image is already in a bitmap. Could you
please elaborate blit the entire thing to your control?For instance what
would that mean for a panel control? Also doing this everytime wont it mean
that for drawing my new stuff i refresh the whole bitmap while i only wanted
to refresh those portions of the screen that contained my old drawing?
 
Thanks much Alex. I will read them throughly. I read that .net compact
framework does not support pixel operations on a bitmap that is a huge
dissappointment. I would have to find a way to get around that one. One way
would be to write an algorithms to construct my own bitmap object from the
given data and then draw it. Suggest me if you know if poeple have created
there own bitmap objects not using from file or other means but from
scratch.
 
Hi Chris,

What could be going wrong if the image (a JPG) that was
copied to the offscreen bitmap and other stuff that was
drawn onto it (polygons) appear as if they were drawn
first to the bitmap, e.g. appear behind the JPG?

Regards,

Jan Klaver
 
I did do offscreen buffering but there is still flashing in the screen. Let
me explain what I am doing. in the pain even handler of the control I have
the following approach

private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs
paintg)
{
Graphics gxOff; //create an Offscreen graphics
if (m_bmpOffscreen == null) //Bitmap for doublebuffering, create if not
created
m_bmpOffscreen = new Bitmap(ClientSize.Width, ClientSize.Height);
//m_bmpOffscreen is a private member of the class
gxOff = Graphics.FromImage(m_bmpOffscreen);//Attach image
gxOff.Clear(this.BackColor);
gxOff.DrawImage(m_bmpOrg, 0, 0, rectBmpOrg, GraphicsUnit.Pixel); // here
I draw my JPG image which fills the cliend area of the control
//this image does not change except when one goes to the file menu and
opens another.
gxOff.DrawPolygon(blackPen, (Point[])rose.GenerateRoseCurvePts());
//this is where I draw the polygon. This is the part that changes with each
mouse down and mouse move.
paintg.Graphics.DrawImage(m_bmpOffscreen, 0, 0);
base.OnPaint(paintg);
}
Rest on the mouse move
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
if (dragging) // if the polygon is being dragged
{
//compute new set of point
panel1.Invalidate(); //Now this causes the paint even to be called
for everymovement of the mouse.
}
}

Where am I going wrong? Is there are a better alternative. can I control the
rate at which refreshing is taking place? the image in the background needs
not be repainted again and again but since I am drawing the polygon on it
and to move the polygon to a new position I need to do it. also how can I
control the rate at which refreshing takes place so that there is no
flicker?
Thanks in anticipation
Abhishek

Abhishek said:
Thanks much Alex. I will read them throughly. I read that .net compact
framework does not support pixel operations on a bitmap that is a huge
dissappointment. I would have to find a way to get around that one. One way
would be to write an algorithms to construct my own bitmap object from the
given data and then draw it. Suggest me if you know if poeple have created
there own bitmap objects not using from file or other means but from
scratch.


Alex Yakhnin said:
There're a few articles on that matter on MSDN:
http://msdn.microsoft.com/library/d...-us/dnnetcomp/html/netcfgaming.asp?frame=true
--
Alex Yakhnin, NET CF MVP
IntelliProg, Inc.
http://www.intelliprog.com

Abhishek said:
Thanks for your reply. My background image is already in a bitmap.
Could
you
please elaborate blit the entire thing to your control?For instance what
would that mean for a panel control? Also doing this everytime wont it mean
that for drawing my new stuff i refresh the whole bitmap while i only wanted
to refresh those portions of the screen that contained my old drawing?
"Chris Tacke, eMVP" <ctacke[at]Open_NET_CF[dot]org> wrote in message
Keep tha background image in a bitmap, draw your new stuff onto that
bitmap,
then blit the entire thing to your control. Be sure to override
OnBackgroundPaint to get better perf.

-Chris

Hello everyone,

I am a newbee & this is my first post so my questions might be
naive
but
I
hope I get helped because I am just started for dotnet for my research.

My objective is to display a jpg image and then overlay on it a
curve
or
a
rectangle that the user can select and modify. I made a panel control,
used
DrawImage, and then added a paint event handler for the panel
control
in
which I drew both the image (using DrawImage ofcourse) and then the
rectangle (using DrawRectangle). I attached a click event with the panel
control which hit-tests the co-ordinates, changes the co-ordinates of
the
rectangle drawn, and calls this.panel1.Invalidate(). This works
but
image
moves
it had it
is which
the
 
Back
Top