.NET Forum / .NET Framework / .NET SDK / May 2004
converting image size
|
|
Thread rating:  |
z f - 10 May 2004 05:47 GMT Hi,
I'm using asp-dot net to upload an image, and saving the image. i get the image object this way: System.Drawing.Image img = System.Drawing.Image.FromStream(file.PostedFile.InputStream);
I also save thumbnail using System.Drawing.Image thumb = img.GetThumbnailImage(width,height,null,IntPtr.Zero);
but i need to save a copy of the image with different size then the original image but larger then the thumbnail. if i try to use the GetThumbnailImage, with bigger size, i get low quality copy.
trying to use the Graphics class I didn't find the way to convert the image size. Graphics g = Graphics.FromImage ( img );
g.WhatFunctionShouldIUse to convert the image size?
or how should it be done?
TIA,
z.
Bob Powell [MVP] - 10 May 2004 10:50 GMT Read the GDI+ FAQ. This has articles that explain what you want to do.
 Signature Bob Powell [MVP] Visual C#, System.Drawing
Image transition effects, automatic persistent configuration and design time mouse operations all in April's issue of Well Formed http://www.bobpowell.net/wellformed.htm
Answer those GDI+ questions with the GDI+ FAQ http://www.bobpowell.net/gdiplus_faq.htm
The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml Bob's Blog: http://royo.is-a-geek.com/siteFeeder/GetFeed.aspx?FeedId=41
Hi,
I'm using asp-dot net to upload an image, and saving the image. i get the image object this way: System.Drawing.Image img = System.Drawing.Image.FromStream(file.PostedFile.InputStream);
I also save thumbnail using System.Drawing.Image thumb = img.GetThumbnailImage(width,height,null,IntPtr.Zero);
but i need to save a copy of the image with different size then the original image but larger then the thumbnail. if i try to use the GetThumbnailImage, with bigger size, i get low quality copy.
trying to use the Graphics class I didn't find the way to convert the image size. Graphics g = Graphics.FromImage ( img );
g.WhatFunctionShouldIUse to convert the image size?
or how should it be done?
TIA,
z.
z. f. - 10 May 2004 12:09 GMT i guess you mean this example: Bitmap bm = (Bitmap)Image.FromFile("myimage.jpg");
Bitmap resized = new Bitmap((int)(0.3f*bm.Width),(int)(0.3f*bm.Height));
Graphics g=Graphics.FromImage(resized);
g.DrawImage(bm, new Rectangle(0,0,resized.Width,resized.Height),0,0,bm.Width,bm.Height,GraphicsUnit.Pixel);
g.Dispose();
resized.Save("resizedimage.jpg",ImageFormat.Jpeg);
Read the GDI+ FAQ. This has articles that explain what you want to do.
-- Bob Powell [MVP] Visual C#, System.Drawing
Image transition effects, automatic persistent configuration and design time mouse operations all in April's issue of Well Formed http://www.bobpowell.net/wellformed.htm
Answer those GDI+ questions with the GDI+ FAQ http://www.bobpowell.net/gdiplus_faq.htm
The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml Bob's Blog: http://royo.is-a-geek.com/siteFeeder/GetFeed.aspx?FeedIdA
"z f" <zigi@info-scope.co.il> wrote in message news:%231fnEGkNEHA.3292@TK2MSFTNGP11.phx.gbl... Hi,
I'm using asp-dot net to upload an image, and saving the image. i get the image object this way: System.Drawing.Image img = System.Drawing.Image.FromStream(file.PostedFile.InputStream);
I also save thumbnail using System.Drawing.Image thumb = img.GetThumbnailImage(width,height,null,IntPtr.Zero);
but i need to save a copy of the image with different size then the original image but larger then the thumbnail. if i try to use the GetThumbnailImage, with bigger size, i get low quality copy.
trying to use the Graphics class I didn't find the way to convert the image size. Graphics g = Graphics.FromImage ( img );
g.WhatFunctionShouldIUse to convert the image size?
or how should it be done?
TIA,
z.
Bob Powell [MVP] - 10 May 2004 12:19 GMT That's one. There are a few others that deal with changing resolutions and drawing images in general.
 Signature Bob Powell [MVP] Visual C#, System.Drawing
Image transition effects, automatic persistent configuration and design time mouse operations all in April's issue of Well Formed http://www.bobpowell.net/wellformed.htm
Answer those GDI+ questions with the GDI+ FAQ http://www.bobpowell.net/gdiplus_faq.htm
The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml Bob's Blog: http://royo.is-a-geek.com/siteFeeder/GetFeed.aspx?FeedIdA
i guess you mean this example: Bitmap bm = (Bitmap)Image.FromFile("myimage.jpg");
Bitmap resized = new Bitmap((int)(0.3f*bm.Width),(int)(0.3f*bm.Height));
Graphics g=Graphics.FromImage(resized);
g.DrawImage(bm, new Rectangle(0,0,resized.Width,resized.Height),0,0,bm.Width,bm.Height,GraphicsUnit.Pixel);
g.Dispose();
resized.Save("resizedimage.jpg",ImageFormat.Jpeg);
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message news:Ov3dKRnNEHA.1956@TK2MSFTNGP10.phx.gbl... Read the GDI+ FAQ. This has articles that explain what you want to do.
-- Bob Powell [MVP] Visual C#, System.Drawing
Image transition effects, automatic persistent configuration and design time mouse operations all in April's issue of Well Formed http://www.bobpowell.net/wellformed.htm
Answer those GDI+ questions with the GDI+ FAQ http://www.bobpowell.net/gdiplus_faq.htm
The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml Bob's Blog: http://royo.is-a-geek.com/siteFeeder/GetFeed.aspx?FeedIdA
"z f" <zigi@info-scope.co.il> wrote in message news:%231fnEGkNEHA.3292@TK2MSFTNGP11.phx.gbl... Hi,
I'm using asp-dot net to upload an image, and saving the image. i get the image object this way: System.Drawing.Image img = System.Drawing.Image.FromStream(file.PostedFile.InputStream);
I also save thumbnail using System.Drawing.Image thumb = img.GetThumbnailImage(width,height,null,IntPtr.Zero);
but i need to save a copy of the image with different size then the original image but larger then the thumbnail. if i try to use the GetThumbnailImage, with bigger size, i get low quality copy.
trying to use the Graphics class I didn't find the way to convert the image size. Graphics g = Graphics.FromImage ( img );
g.WhatFunctionShouldIUse to convert the image size?
or how should it be done?
TIA,
z.
z. f. - 11 May 2004 07:36 GMT thanx, it worked,
can i control the quality of the result image?, because i notices that when internet explorer shows the image smaller it is shown in better quality then after resized by the code.
i guess you mean this example: Bitmap bm = (Bitmap)Image.FromFile("myimage.jpg");
Bitmap resized = new Bitmap((int)(0.3f*bm.Width),(int)(0.3f*bm.Height));
Graphics g=Graphics.FromImage(resized);
g.DrawImage(bm, new Rectangle(0,0,resized.Width,resized.Height),0,0,bm.Width,bm.Height,GraphicsUnit.Pixel);
g.Dispose();
resized.Save("resizedimage.jpg",ImageFormat.Jpeg);
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message news:Ov3dKRnNEHA.1956@TK2MSFTNGP10.phx.gbl... Read the GDI+ FAQ. This has articles that explain what you want to do.
-- Bob Powell [MVP] Visual C#, System.Drawing
Image transition effects, automatic persistent configuration and design time mouse operations all in April's issue of Well Formed http://www.bobpowell.net/wellformed.htm
Answer those GDI+ questions with the GDI+ FAQ http://www.bobpowell.net/gdiplus_faq.htm
The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml Bob's Blog: http://royo.is-a-geek.com/siteFeeder/GetFeed.aspx?FeedIdA
"z f" <zigi@info-scope.co.il> wrote in message news:%231fnEGkNEHA.3292@TK2MSFTNGP11.phx.gbl... Hi,
I'm using asp-dot net to upload an image, and saving the image. i get the image object this way: System.Drawing.Image img = System.Drawing.Image.FromStream(file.PostedFile.InputStream);
I also save thumbnail using System.Drawing.Image thumb = img.GetThumbnailImage(width,height,null,IntPtr.Zero);
but i need to save a copy of the image with different size then the original image but larger then the thumbnail. if i try to use the GetThumbnailImage, with bigger size, i get low quality copy.
trying to use the Graphics class I didn't find the way to convert the image size. Graphics g = Graphics.FromImage ( img );
g.WhatFunctionShouldIUse to convert the image size?
or how should it be done?
TIA,
z.
Bob Powell [MVP] - 11 May 2004 09:38 GMT If you're referring to the compression quality of the saved JPEG yes you can.
The GDI+ FAQ has an article for that too :-))
http://www.bobpowell.net/jpeg_compression.htm
 Signature Bob Powell [MVP] Visual C#, System.Drawing
Image transition effects, automatic persistent configuration and design time mouse operations all in April's issue of Well Formed http://www.bobpowell.net/wellformed.htm
Answer those GDI+ questions with the GDI+ FAQ http://www.bobpowell.net/gdiplus_faq.htm
The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml Bob's Blog: http://royo.is-a-geek.com/siteFeeder/GetFeed.aspx?FeedIdA
thanx, it worked,
can i control the quality of the result image?, because i notices that when internet explorer shows the image smaller it is shown in better quality then after resized by the code.
i guess you mean this example: Bitmap bm = (Bitmap)Image.FromFile("myimage.jpg");
Bitmap resized = new Bitmap((int)(0.3f*bm.Width),(int)(0.3f*bm.Height));
Graphics g=Graphics.FromImage(resized);
g.DrawImage(bm, new Rectangle(0,0,resized.Width,resized.Height),0,0,bm.Width,bm.Height,GraphicsUnit.Pixel);
g.Dispose();
resized.Save("resizedimage.jpg",ImageFormat.Jpeg);
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message news:Ov3dKRnNEHA.1956@TK2MSFTNGP10.phx.gbl... Read the GDI+ FAQ. This has articles that explain what you want to do.
-- Bob Powell [MVP] Visual C#, System.Drawing
Image transition effects, automatic persistent configuration and design time mouse operations all in April's issue of Well Formed http://www.bobpowell.net/wellformed.htm
Answer those GDI+ questions with the GDI+ FAQ http://www.bobpowell.net/gdiplus_faq.htm
The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml Bob's Blog: http://royo.is-a-geek.com/siteFeeder/GetFeed.aspx?FeedIdA
"z f" <zigi@info-scope.co.il> wrote in message news:%231fnEGkNEHA.3292@TK2MSFTNGP11.phx.gbl... Hi,
I'm using asp-dot net to upload an image, and saving the image. i get the image object this way: System.Drawing.Image img = System.Drawing.Image.FromStream(file.PostedFile.InputStream);
I also save thumbnail using System.Drawing.Image thumb = img.GetThumbnailImage(width,height,null,IntPtr.Zero);
but i need to save a copy of the image with different size then the original image but larger then the thumbnail. if i try to use the GetThumbnailImage, with bigger size, i get low quality copy.
trying to use the Graphics class I didn't find the way to convert the image size. Graphics g = Graphics.FromImage ( img );
g.WhatFunctionShouldIUse to convert the image size?
or how should it be done?
TIA,
z.
Free MagazinesGet 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 ...
|
|
|