Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / August 2004

Tip: Looking for answers? Try searching our database.

newbie and DrawImage

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dan - 26 Aug 2004 16:29 GMT
My application has a form which should display an image at an arbitrary zoom
factor, and optionally draw other images (like layers in Photoshop) onto the
'base' image. The easiest way I can think of could be e.g.:

----OnPaint handler:
// keep into account scrollbar position
g.TranslateTransform(AutoScrollPosition.X, AutoScrollPosition.Y);

// calculate the destination rectangle scaled according to _fScale
(1.0=100%, 0.5=50%, etc)
Rectangle rctImage = new Rectangle(0, 0,
(int)(_bmpBase.Width * _fScale), (int)(_bmpBase.Height * _fScale));

// draw the base image
g.DrawImage(_bmpBase, rctImage);

// draw layers onto it with opacity value _fOpacity (1=100%)
foreach (bmp in layersCollection)
{
ColorMatrix cm = new ColorMatrix();
cm.Matrix33 = _fOpacity;
ImageAttributes ia = new ImageAttributes();
ia.SetColorMatrix(cm, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
g.DrawImage(bmp, rctImage,
 0, 0,
 _bmpBase.Width, _bmpBase.Height,
 GraphicsUnit.Pixel, ia);
}

This works, but cannot be an optimal way of doing it, as the program slows
down when the image is big (e.g. 2000x2000 pixels). I thought I could gain
performance by drawing not the whole image(s) but only the portion required
for display. Thus I have written this demo which just shows an image onto a
form using a smaller source rectangle:

Rectangle rctSrc = new Rectangle(
Math.Abs(AutoScrollPosition.X), Math.Abs(AutoScrollPosition.Y),
(int)((float)ClientSize.Width / _fScale),
(int)((float)ClientSize.Height / _fScale));

g.DrawImage(_bmp, ClientRectangle, rctSrc.X, rctSrc.Y, rctSrc.Width,
rctSrc.Height,
GraphicsUnit.Pixel);

This works BUT when scrolling with the 'arrows' (not dragging the thumb)
creates display errors on the sides opposite to the direction of scrolling.
If I minimize and then restore the form this problem is fixed, so it must be
related to the scrolling logic when scrolling 'smoothly'. How can I fix
this? And more generally, how can I gain true performance when drawing
'overlapped' images? My attempt could be effective, or I should just think
of other ways for optimizing?

Thanx to all!
Supra - 27 Aug 2004 14:38 GMT
http://www.vbdotnetheaven.com/

>My application has a form which should display an image at an arbitrary zoom
>factor, and optionally draw other images (like layers in Photoshop) onto the
[quoted text clipped - 49 lines]
>
>Thanx to all!
Dan - 27 Aug 2004 15:07 GMT
Thanks, nice site! Anyway, the article does not respond to my question, that
is, it shows an example of image drawing where DrawImage is simply called to
show the whole image. I don't know if reducing the source image rectangle
could be beneficial, anyway I cannot go this way unless I manage to solve
the scroll issue I was talking about. Or is there any effective technique to
speed up image drawing in my case?

> http://www.vbdotnetheaven.com/
>
[quoted text clipped - 51 lines]
> >
> >Thanx to all!
Supra - 30 Aug 2004 10:42 GMT
to show whole image. u will have to create another procedure events. i
used tow procedure events one for small and and one for whole image. but
i used user control.
regards

>Thanks, nice site! Anyway, the article does not respond to my question, that
>is, it shows an example of image drawing where DrawImage is simply called to
[quoted text clipped - 107 lines]
>>>
>>>Thanx to all!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.