BitmapExtensionsResize(Bitmap, Size, ScalingMode, Boolean) Method
Resizes the image using the specified
scalingMode. The result always has a
Format32bppPArgb pixel format.
Namespace: KGySoft.DrawingAssembly: KGySoft.Drawing (in KGySoft.Drawing.dll) Version: 10.0.0-rc.1
public static Bitmap Resize(
this Bitmap image,
Size newSize,
ScalingMode scalingMode,
bool keepAspectRatio = false
)
<ExtensionAttribute>
Public Shared Function Resize (
image As Bitmap,
newSize As Size,
scalingMode As ScalingMode,
Optional keepAspectRatio As Boolean = false
) As Bitmap
public:
[ExtensionAttribute]
static Bitmap^ Resize(
Bitmap^ image,
Size newSize,
ScalingMode scalingMode,
bool keepAspectRatio = false
)
[<ExtensionAttribute>]
static member Resize :
image : Bitmap *
newSize : Size *
scalingMode : ScalingMode *
?keepAspectRatio : bool
(* Defaults:
let _keepAspectRatio = defaultArg keepAspectRatio false
*)
-> Bitmap
- image Bitmap
- The original image to resize
- newSize Size
- The requested new size.
- scalingMode ScalingMode
- A ScalingMode value, which determines the quality of the result as well as the processing time.
- keepAspectRatio Boolean (Optional)
- to keep aspect ratio of the source image; otherwise, . This parameter is optional.
Default value: .
BitmapA
Bitmap instance with the new size.In Visual Basic and C#, you can call this method as an instance method on any object of type
Bitmap. When you use instance method syntax to call this method, omit the first parameter. For more information, see
Extension Methods (Visual Basic) or
Extension Methods (C# Programming Guide).
This method adjusts the degree of parallelization automatically, blocks the caller, and does not support cancellation or reporting progress.
Use the
BitmapDataExtensions.BeginResize
or
BitmapDataExtensions.ResizeAsync
(in .NET Framework 4.0 and above) methods for asynchronous call and to adjust parallelization, set up cancellation and for reporting progress.
Assuming that the result will be most likely rendered by GDI+, this method always produces a result with Format32bppPArgb PixelFormat, and performs the operation
in the sRGB color space. To resize an image with a custom pixel format create a new Bitmap with the Bitmap(Int32, Int32, PixelFormat) constructor using
the desired pixel format and size, obtain a readable bitmap data from the source image and a read-write bitmap data from the newly created target image
by the GetReadableBitmapData(Bitmap, Color, Byte) and GetReadWriteBitmapData(Bitmap, WorkingColorSpace, Color, Byte) methods respectively,
and use the DrawInto extension methods. To perform the operation in the linear color space
just pass WorkingColorSpace.Linear as the working color space when obtaining the target bitmap data.