Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.11/5 (2 votes)
See more:
Hi I have a function where I get an InterpolationMode value from the user:

VB
Public Function EncodeImage(ByVal input As Image,ByVal output As String,Optional interpolation As InterpolationMode = InterpolationMode.HighQualityBicubic) As Image

I can't seem to work out how to actually get the value when it is set though.

What I have tried:

I have tried something like:
VB
If interpolation Then graphicsHandle.InterpolationMode = interpolation
But it doesn't give the value.

Any clues would be much appreciated. Thanks!
Posted
Updated 6-Jul-18 8:37am
v2
Comments
phil.o 7-Jun-18 1:33am    
Get the value from where? Interpolation mode is only used by Graphics objects when images are to be scaled or rotated; it is not saved in the image itself.
So, whether you use it in the function where it has been passed as a parameter, or you store it in a global variable if you want to remember it for further operations.

The context in which you want to retrieve this value is unclear.

1 solution

First of all, this can be improved by removing ByVal, as it's the default anyway:
VB
Public Function EncodeImage(ByVal input As Image,ByVal output As String,Optional interpolation As InterpolationMode = InterpolationMode.HighQualityBicubic) As Image
VB
Public Function EncodeImage(input As Image, output As String, Optional interpolation As InterpolationMode = InterpolationMode.HighQualityBicubic) As Image

This could also be logically improved:
VB
If interpolation Then graphicsHandle.InterpolationMode = interpolation
VB
graphicsHandle.InterpolationMode = interpolation

As well as being less efficient, the first one would cause an error because you're comparing an InterpolationMode to true/false, and it cannot be compared as such.

If you're trying to set the InterpolationMode of something and it's been passed as the parameter of the function, as you've got set up already, you can just do the above to use it;
VB
graphicsHandle.InterpolationMode = interpolation

What you may be confused about is the Optional keyword. It means you can choose to specify a value which overrides the default value, or you can leave it, and the default is used.

This means you can both of the following scenarios:
VB
Dim myImg As New Bitmap()
Dim img As Bitmap = EncodeImage(myImg, "this is the output") ' interpolation left blank so it will default to InterpolationMode.HighQualityBicubic
VB
Dim myImg As New Bitmap()
Dim img As Bitmap = EncodeImage(myImg, "this is the output", InterpolationMode.SomethingElse)
 
Share this answer
 
v9

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900