Hi David,
Any further progress on this issue? if there're anything else we can help,
please feel free to post here.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| X-Tomcat-ID: 53188289
| References: <#r************ **@TK2MSFTNGP09 .phx.gbl>
<#G************ **@TK2MSFTNGP09 .phx.gbl>
<v1************ **@TK2MSFTNGXA0 2.phx.gbl>
<O3************ **@TK2MSFTNGP15 .phx.gbl>
<O$************ **@TK2MSFTNGP15 .phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
| From:
st*****@online. microsoft.com (Steven Cheng[MSFT])
| Organization: Microsoft
| Date: Tue, 13 Dec 2005 02:45:03 GMT
| Subject: Re: Upload image and then resize it - A generic error occurred
in GDI+.
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
| Message-ID: <Mh************ **@TK2MSFTNGXA0 2.phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| Lines: 268
| Path: TK2MSFTNGXA02.p hx.gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3644 16
| NNTP-Posting-Host: tomcatimport2.p hx.gbl 10.201.218.182
|
| Thanks for your response David,
|
| I think the NullReference exception is due to the graphic object is not
| correctly assigned. From the code you pasted:
|
| =============== ==
| Dim graphic As Graphics
| graphic.FromIma ge(photo)
| Dim img2 As Image
| graphic.DrawIma ge(img, New Rectangle(0, 0, nw, nh), New
| Rectangle(0, 0, iw, ih), GraphicsUnit.Pi xel)
|
| graphic.Dispose ()
| photo.Save(p)
| =============== ==
|
| You use graphic.FromIma ge(photo), this will return an Graphics object
| instance, and you need to assign it to the Graphics reference, like:
|
|
| ........
| Dim graphic As Graphics
| graphic = Graphics.FromIm age(photo)
| ............
|
|
| Thanks,
|
| Steven Cheng
| Microsoft Online Support
|
| Get Secure!
www.microsoft.com/security
| (This posting is provided "AS IS", with no warranties, and confers no
| rights.)
|
|
|
|
| --------------------
| | From: "David Lozzi" <Da********@nos pam.nospam>
| | References: <#r************ **@TK2MSFTNGP09 .phx.gbl>
| <#G************ **@TK2MSFTNGP09 .phx.gbl>
| <v1************ **@TK2MSFTNGXA0 2.phx.gbl>
| <O3************ **@TK2MSFTNGP15 .phx.gbl>
| | Subject: Re: Upload image and then resize it - A generic error occurred
| in GDI+.
| | Date: Mon, 12 Dec 2005 09:40:02 -0500
| | Lines: 229
| | X-Priority: 3
| | X-MSMail-Priority: Normal
| | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| | X-RFC2646: Format=Flowed; Response
| | Message-ID: <O$************ **@TK2MSFTNGP15 .phx.gbl>
| | Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| | NNTP-Posting-Host: c-24-63-42-200.hsd1.ma.com cast.net 24.63.42.200
| | Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP15.phx. gbl
| | Xref: TK2MSFTNGXA02.p hx.gbl
| microsoft.publi c.dotnet.framew ork.aspnet:3642 19
| | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
| |
| | The object reference error is occuring on the DrawImage line, if that
| helps.
| |
| | --
| | David Lozzi
| | Web Applications Developer
| |
dlozzi@(remove-this)delphi-ts.com
| |
| |
| |
| | "David Lozzi" <Da********@nos pam.nospam> wrote in message
| | news:O3******** ******@TK2MSFTN GP15.phx.gbl...
| | > After reviewing your code, this function returns the resized image as
| an
| | > image to the calling script. I need the resized image to be saved to
| disk.
| | > My script is below. I get an error: Object reference not set to an
| | > instance of an object, which pertains to the graphic object because
| when I
| | > remove that chunk of code, I get the same GDI+ error.
| | >
| | > Thanks!!
| | >
| | > Function ResizeImage(ByV al p As String, ByVal w As Integer, ByVal
h
| As
| | > Integer) As String
| | > Dim img As System.Drawing. Image
| | > img = System.Drawing. Image.FromFile( p)
| | > Dim iw As Integer = img.Width
| | > Dim ih As Integer = img.Height
| | > Dim nw, nh As Integer
| | > Dim per As Decimal
| | >
| | > If iw > w Or ih > h Then 'check to see if resize is necessary
| | > If iw > ih Then 'get the larger dimension and get
percentage
| | > per = w / iw
| | > Else
| | > per = h / ih
| | > End If
| | >
| | > 'create new sizes based on percentages
| | > nw = iw * per
| | > nh = ih * per
| | >
| | > 'now save it
| | > Dim photo As New Bitmap(nw, nh,
| | > Imaging.PixelFo rmat.Format24bp pRgb)
| | > photo.SetResolu tion(img.Horizo ntalResolution,
| | > img.VerticalRes olution)
| | > Dim graphic As Graphics
| | > graphic.FromIma ge(photo)
| | > Dim img2 As Image
| | > graphic.DrawIma ge(img, New Rectangle(0, 0, nw, nh), New
| | > Rectangle(0, 0, iw, ih), GraphicsUnit.Pi xel)
| | >
| | > graphic.Dispose ()
| | > photo.Save(p)
| | >
| | > lblTemp.Text = "<br>Per " & per & "<br>Old " & iw & "x" &
ih
| &
| | > "<br>New " & nw & "x" & nh
| | > Else
| | > lblTemp.Text = "No resize necessary."
| | > End If
| | > End Function
| | >
| | > --
| | > David Lozzi
| | > Web Applications Developer
| | >
dlozzi@(remove-this)delphi-ts.com
| | >
| | >
| | >
| | > "Steven Cheng[MSFT]" <st*****@online .microsoft.com> wrote in message
| | > news:v1******** ********@TK2MSF TNGXA02.phx.gbl ...
| | >> Hey David,
| | >>
| | >> So this seems a pure GDI+ image processing issue. Does this problem
| | >> occurs
| | >> only when the uploaded image is of certain format or is a common
issue
| | >> that
| | >> will occur for any images that uploaded onto the server? Generally I
| | >> think
| | >> we can throubleshoot through the following steps:
| | >>
| | >> 1. Make sure that the image is uploaded correctly onto the server ,
| open
| | >> it
| | >> in image viewer to make sure the data is not corrupted.
| | >>
| | >> 2. Then, use some standard image resizeing code to resize the
image...
| | >> here is some simple GDI+ code I picked from net which resize the
image
| | >> through percentage value:
| | >>
| | >> static Image ScaleByPercent( Image imgPhoto, int Percent)
| | >> {
| | >> float nPercent = ((float)Percent/100);
| | >>
| | >> int sourceWidth = imgPhoto.Width;
| | >> int sourceHeight = imgPhoto.Height ;
| | >> int sourceX = 0;
| | >> int sourceY = 0;
| | >>
| | >> int destX = 0;
| | >> int destY = 0;
| | >> int destWidth = (int)(sourceWid th * nPercent);
| | >> int destHeight = (int)(sourceHei ght * nPercent);
| | >>
| | >> Bitmap bmPhoto = new Bitmap(destWidt h, destHeight,
| | >> PixelFormat.For mat24bppRgb);
| | >> bmPhoto.SetReso lution(imgPhoto .HorizontalReso lution,
| | >> imgPhoto.Vertic alResolution);
| | >>
| | >> Graphics grPhoto = Graphics.FromIm age(bmPhoto);
| | >> grPhoto.Interpo lationMode = InterpolationMo de.HighQualityB icubic;
| | >>
| | >> grPhoto.DrawIma ge(imgPhoto,
| | >> new Rectangle(destX ,destY,destWidt h,destHeight),
| | >> new Rectangle(sourc eX,sourceY,sour ceWidth,sourceH eight),
| | >> GraphicsUnit.Pi xel);
| | >>
| | >> grPhoto.Dispose ();
| | >> return bmPhoto;
| | >> }
| | >>
| | >> You can try resizing through the code also to see whether it can
work
| | >> correctly....
| | >>
| | >> If there're any other finding, please feel free to post here.
| | >>
| | >> Thanks,
| | >>
| | >> Steven Cheng
| | >> Microsoft Online Support
| | >>
| | >> Get Secure!
www.microsoft.com/security
| | >> (This posting is provided "AS IS", with no warranties, and confers no
| | >> rights.)
| | >>
| | >>
| | >>
| | >> --------------------
| | >> | From: "David Lozzi" <Da********@nos pam.nospam>
| | >> | References: <#r************ **@TK2MSFTNGP09 .phx.gbl>
| | >> | Subject: Re: Upload image and then resize it - A generic error
| occurred
| | >> in GDI+.
| | >> | Date: Fri, 9 Dec 2005 11:15:17 -0500
| | >> | Lines: 270
| | >> | MIME-Version: 1.0
| | >> | Content-Type: multipart/alternative;
| | >> | boundary="----=_NextPart_000_ 0011_01C5FCB1.D 5B1AFD0"
| | >> | X-Priority: 3
| | >> | X-MSMail-Priority: Normal
| | >> | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| | >> | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| | >> | Message-ID: <#G************ **@TK2MSFTNGP09 .phx.gbl>
| | >> | Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| | >> | NNTP-Posting-Host: c-24-63-42-200.hsd1.ma.com cast.net 24.63.42.200
| | >> | Path:
TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP09.phx. gbl
| | >> | Xref: TK2MSFTNGXA02.p hx.gbl
| | >> microsoft.publi c.dotnet.framew ork.aspnet:3638 64
| | >> | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
| | >> |
| | >> | Besides the point, I just realized my math is wrong, please don't
| | >> critique. I just need to resolve the resize issue.
| | >> | --
| | >> | David Lozzi
| | >> | Web Applications Developer
| | >> |
dlozzi@(remove-this)delphi-ts.com
| | >> | "David Lozzi" <Da********@nos pam.nospam> wrote in message
| | >> news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
| | >> | Howdy,
| | >> | I have a function that uploads an image and that works great. I
| love
| | >> Nets built in upload, so much easier than 3rd party uploaders!
| | >> | Now I am making a public function that will take the path of the
| | >> uploaded image, and resize it with the provided dimensions. My
| function
| | >> is
| | >> below. The current function is returning an error when run from the
| | >> upload
| | >> function: A generic error occurred in GDI+. Not sure what exactly
that
| | >> means. From what I can tell, no one really knows what it means....
| Here's
| | >> my public function
| | >> | Function ResizeImage(ByV al p As String, ByVal w As Integer,
| ByVal
| | >> h
| | >> As Integer) As String
| | >> | Dim img As System.Drawing. Image
| | >> | img = System.Drawing. Image.FromFile( p)
| | >> | Dim iw As Integer = img.Width
| | >> | Dim ih As Integer = img.Height
| | >> | Dim nw, nh As Integer
| | >> | Dim per As Decimal
| | >> | If iw > w Or ih > h Then 'check to see if resize is
| necessary
| | >> | If w > h Then 'get the larger dimension and get
| | >> percentage
| | >> | per = iw / w
| | >> | Else
| | >> | per = ih / h
| | >> | End If
| | >> | 'create new sizes based on percentages
| | >> | nw = iw * per
| | >> | nh = ih * per
| | >> | 'now save it
| | >> | Dim size As New Size(nw, nh)
| | >> | Dim nimg As New Bitmap(img, size)
| | >> | nimg.Save(p)
| | >> | lblTemp.Text = "<br>Old " & iw & "x" & ih & "<br>New
"
| &
| | >> nw
| | >> & "x" & nh
| | >> | Else
| | >> | lblTemp.Text = "No resize necessary."
| | >> | End If
| | >> | End Function
| | >> | and here is my code for the upload, abbreviated
| | >> | If picType = "image/jpeg" Or picType =
"image/gif"
| Or
| | >> picType = "image/pjpeg" Or picType = "image/bmp" Then
| | >> | File.PostedFile .SaveAs(path)
| | >> | ResizeImage(pat h, 120, 95)
| | >> | lblError.Text = "The speaker photo uploaded
| | >> sucessfully! Make sure to click Update below to save changes."
| | >> | Else
| | >> | lblError.Text = "Invalid image format. Only
| JPG,
| | >> JPEG, GIF and BMP images are allowed."
| | >> | End If
| | >> | Again, the upload works great
| | >> | Thanks!!
| | >> | --
| | >> | David Lozzi
| | >> | Web Applications Developer
| | >> |
dlozzi@(remove-this)delphi-ts.com
| | >> |
| | >> |
| | >>
| | >
| | >
| |
| |
| |
|
|