Home All Groups Group Topic Archive Search About

A few GDI+ U/I questions

Author
2 Apr 2005 9:40 PM
SStory
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 want to do it,
I would like to offer the ability.

Question #2)  I have my cropping working, using my own rubber banding
selector widget, but I am wondering how to best allow them to hold SHIFT and
maintain aspect ratio like Photoshop and others do?  Any ideas on the math,
algorithm needed to do this.  I'm sure it is simple just having one of those
days where I can't think of how to do it.

Thanks a lot,

Shane

Author
2 Apr 2005 11:58 PM
Bob Powell [MVP]
#1 GDI+ FAQ

#2 Just use the X value of the mouse and make the rectangle height the the
width multiplied by the original width divide by the original height.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





Show quoteHide quote
"SStory" <TheStorys@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message
news:%23bqFax8NFHA.604@TK2MSFTNGP10.phx.gbl...
> 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 want to do
> it,
> I would like to offer the ability.
>
> Question #2)  I have my cropping working, using my own rubber banding
> selector widget, but I am wondering how to best allow them to hold SHIFT
> and
> maintain aspect ratio like Photoshop and others do?  Any ideas on the
> math,
> algorithm needed to do this.  I'm sure it is simple just having one of
> those
> days where I can't think of how to do it.
>
> Thanks a lot,
>
> Shane
>
>
Author
3 Apr 2005 9:48 PM
smith
Mr. Powell is indeed "The Man", up there with Rod Stephens and Richard
Mansfield for gdi information, but a from-here quickie on #1 is to call
GC.Collect.  .Net locks the .FronFile opened file "in case it needs to
dynamically get more data" (as in for a multipage Tiff).  However, if you
have grabbed the image and are holdng a clone then that lock gets in the
way.  This is one of the few cases where calling GC.Collect - just after
loading the image to a local object - is a good solution.

Humbly:  maybe the free Adobe eBook mentioned on this page would be of
interest?  http://www.smithvoice.com/ispec_1.aspx

robert smith
kirkland, wa
www.smithvoice.com

Show quoteHide quote
"SStory" <TheStorys@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message
news:%23bqFax8NFHA.604@TK2MSFTNGP10.phx.gbl...
> 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 want to do
> it,
> I would like to offer the ability.
>
> Question #2)  I have my cropping working, using my own rubber banding
> selector widget, but I am wondering how to best allow them to hold SHIFT
> and
> maintain aspect ratio like Photoshop and others do?  Any ideas on the
> math,
> algorithm needed to do this.  I'm sure it is simple just having one of
> those
> days where I can't think of how to do it.
>
> Thanks a lot,
>
> Shane
>
>