Problem with syntax..HELP

G

Guest

Can someone please help! I have an error in the following bit of code and would appritiate any help

Thanks

System.Drawing.Bitmap outputImage = new System.Drawing.Bitmap(origBitmap, newWidth, newHeight)
System.IO.MemoryStream io = new System.IO.MemoryStream()
outputImage.Save(io, Server.MapPath(basePath + System.IO.Path.GetFileName(_FileName.Value)),System.Drawing.Imaging.ImageFormat.Jpeg)
Response.BinaryWrite( io.GetBuffer() )
outputImage.Dispose()

...::ERROR::.
Compiler Error Message: CS1502: The best overloaded method match for 'System.Drawing.Image.Save(System.IO.Stream, System.Drawing.Imaging.ImageCodecInfo, System.Drawing.Imaging.EncoderParameters)' has some invalid arguments
 
G

Guest

Hi
I tried to acheive the same functionality using the following code. Dont know the performance bottlenecks but it works ;
Dim imgToBeCropped As Image = System.Drawing.Image.FromFile("c:\mypic.jpg"
Dim bmpImage As Bitmap = New Bitmap(imgToBeCropped

Dim bmpCrop As Bitmap = New Bitmap(20, 20, bmpImage.PixelFormat
Dim grpCrop As Graphics = Graphics.FromImage(bmpCrop
Dim rectDest As Rectangle = New Rectangle(0, 0, 20, 20
grpCrop.DrawImage(bmpImage, rectDest
bmpCrop.Save("c:\mypic1.jpg", System.Drawing.Imaging.ImageFormat.Jpeg
suggest if i m commiting a serious mistake, but it works
the bes
srini
 
G

Guest

Hi

My code works fine if I don't stream it but as soon as I add the stream it screws up and I get the error mentioned previously! Thanks for the advise
 
G

Guest

For stream, you have to watch out the syntax
You will either use
public void Save(Stream, ImageFormat)
O
public void Save(Stream, ImageCodecInfo, EncoderParameters)
In your case
outputImage.Save(io, System.Drawing.Imaging.ImageFormat.Jpeg)
Drop the "Server.MapPath(basePath + System.IO.Path.GetFileName(_FileName.Value))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top