How To Resize A Image Using C# Or VB.NET - CODE SNIPPETS
Có thể bạn quan tâm
Skip to content .NET C# VB.Net How to resize a image using C# or VB.NET
ByAdministrator
Jun 2, 2014 .net, bitmap, C#, csharp, Drawing, image, resize, System, System.Drawing, vb.net, Visual Studio 2005, Visual Studio 2008, Visual Studio 2010, Visual Studio 2012, Visual Studio 2013To resize a image using C# or VB.NET you can use the following snippet.
Sample C#
public static Image ResizeImage(Image img, int width, int height) { var newImage = new Bitmap(width, height); using (var gr = Graphics.FromImage(newImage)) { gr.SmoothingMode = SmoothingMode.HighQuality; gr.InterpolationMode = InterpolationMode.HighQualityBicubic; gr.PixelOffsetMode = PixelOffsetMode.HighQuality; gr.DrawImage(img, new Rectangle(0, 0, width, height)); } return newImage; } public static Image ResizeImage(Image img, Size size) { return ResizeImage(img, size.Width, size.Height); } public static Image ResizeImage(Bitmap bmp, int width, int height) { return ResizeImage((Image)bmp, width, height); } public static Image ResizeImage(Bitmap bmp, Size size) { return ResizeImage((Image)bmp, size.Width, size.Height); }Sample VB.NET
Public Shared Function ResizeImage(img As Image, width As Integer, height As Integer) As Image Dim newImage = New Bitmap(width, height) Using gr = Graphics.FromImage(newImage) gr.SmoothingMode = SmoothingMode.HighQuality gr.InterpolationMode = InterpolationMode.HighQualityBicubic gr.PixelOffsetMode = PixelOffsetMode.HighQuality gr.DrawImage(img, New Rectangle(0, 0, width, height)) End Using Return newImage End Function Public Shared Function ResizeImage(img As Image, size As Size) As Image Return ResizeImage(img, size.Width, size.Height) End Function Public Shared Function ResizeImage(bmp As Bitmap, width As Integer, height As Integer) As Image Return ResizeImage(DirectCast(bmp, Image), width, height) End Function Public Shared Function ResizeImage(bmp As Bitmap, size As Size) As Image Return ResizeImage(DirectCast(bmp, Image), size.Width, size.Height) End FunctionHere are the same methods as Extensions Methods
Sample C#
public static Image ResizeImage(this Image img, int width, int height) { var newImage = new Bitmap(width, height); using (var gr = Graphics.FromImage(newImage)) { gr.SmoothingMode = SmoothingMode.HighQuality; gr.InterpolationMode = InterpolationMode.HighQualityBicubic; gr.PixelOffsetMode = PixelOffsetMode.HighQuality; gr.DrawImage(img, new Rectangle(0, 0, width, height)); } return newImage; } public static Image ResizeImage(this Image img, Size size) { return ResizeImage(img, size.Width, size.Height); } public static Image ResizeImage(this Bitmap bmp, int width, int height) { return ResizeImage((Image)bmp, width, height); } public static Image ResizeImage(this Bitmap bmp, Size size) { return ResizeImage((Image)bmp, size.Width, size.Height); }Sample VB.NET
<System.Runtime.CompilerServices.Extension> _ Public Shared Function ResizeImage(img As Image, width As Integer, height As Integer) As Image Dim newImage = New Bitmap(width, height) Using gr = Graphics.FromImage(newImage) gr.SmoothingMode = SmoothingMode.HighQuality gr.InterpolationMode = InterpolationMode.HighQualityBicubic gr.PixelOffsetMode = PixelOffsetMode.HighQuality gr.DrawImage(img, New Rectangle(0, 0, width, height)) End Using Return newImage End Function <System.Runtime.CompilerServices.Extension> _ Public Shared Function ResizeImage(img As Image, size As Size) As Image Return ResizeImage(img, size.Width, size.Height) End Function <System.Runtime.CompilerServices.Extension> _ Public Shared Function ResizeImage(bmp As Bitmap, width As Integer, height As Integer) As Image Return ResizeImage(DirectCast(bmp, Image), width, height) End Function <System.Runtime.CompilerServices.Extension> _ Public Shared Function ResizeImage(bmp As Bitmap, size As Size) As Image Return ResizeImage(DirectCast(bmp, Image), size.Width, size.Height) End FunctionPost navigation
How to change Checkstate of an item in a checkedlistbox control in C# or VB.NET How to use the DebuggerDisplay AttributBy Administrator
Related Post
.NET C# Devexpress VB.NetHow to export Gridview data to Excel using devexpress XtraGrid
Nov 28, 2015 Administrator .NET C# VB.NetHow to catch specific MS-SQL SQLExceptions in C# and VB.NET
Nov 20, 2015 Administrator .NET C# VB.NetHow to extract a password protected zip file using DotNetZip in C# and VB.NET
Nov 12, 2015 AdministratorOne thought on “How to resize a image using C# or VB.NET”
-
RT @CodeSnippetsNET: How to resize a image using C# or http://t.co/85naMTtT4u: http://t.co/g8Jj6WRS7j #csharp #vb #dotnet #winforms #progra…
Log in to Reply
Leave a Reply Cancel reply
You must be logged in to post a comment.
Search
Categories
- .NET
- Android
- AngularJs
- Announcements
- Batch
- C
- C#
- C-PlusPlus
- CSS
- Devexpress
- HTML / HTTP / WEB
- ios
- Java
- Javascript
- jQuery
- Microsoft SQL Server
- Mobile
- Most Read Articles
- MySql
- NuGet
- Objective-C
- Oracle
- PHP
- Powershell
- Python
- Regex
- Ruby
- SQLite
- VB.Net
- VB6
- VBA
- VBScript
- Wordpress
- XML
- XSD
- XSL
Meta
- Log in
- Entries feed
- Comments feed
- WordPress.org
Archives
- August 2016
- June 2016
- December 2015
- November 2015
- September 2015
- August 2015
- July 2015
- June 2015
- May 2015
- April 2015
- March 2015
- February 2015
- January 2015
- November 2014
- August 2014
- July 2014
- June 2014
- May 2014
Từ khóa » Visual Basic Stretch Image
-
How To Set Stretch Property Of An Image - MSDN - Microsoft
-
Image.Stretch Property (System.Windows.Controls) | Microsoft Docs
-
HowTo: Stretch A PictureBox Image To Fit The Control - VB Helper
-
Resizing Images In VB.NET - Stack Overflow
-
How To Stretch An Image In Picturebox In Visual Basic 6?
-
[RESOLVED] Image Stretch Or Reduced To Fit Inside Button In VB.NET
-
Resize Image To Fit In Picturebox - CodeProject
-
Stretch Image To Fit PictureBox At Runtime - Visual Basic .NET - Bytes
-
Resizing Images With Visual Basic (VB6) And CsXImage - Chestysoft
-
How To Stretch An Image In Picturebox? [SOLVED] - DaniWeb
-
Change An Image's Stretch Margins At Run Time - Infragistics
-
Visual Basic, Auto Stretch A Image In Picturebox To A Correct Ratio
-
How To Resize An Image In The ToolStrip Menu Using VB.Net
-
Thread: Resize Image Resolution In Vb6 - CodeGuru Forums