如何从函数中获取interpolationmode值 [英] How to get interpolationmode value from function

查看:119
本文介绍了如何从函数中获取interpolationmode值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有一个函数,我从用户那里得到一个InterpolationMode值:



Hi I have a function where I get an InterpolationMode value from the user:

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:

If interpolation Then graphicsHandle.InterpolationMode = interpolation

但确实如此没有给出价值。



任何线索都会非常感激。谢谢!

But it doesn't give the value.

Any clues would be much appreciated. Thanks!

推荐答案

首先,这可以通过删除ByVal来改进,因为它是默认值:

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

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



这也可以从逻辑上进行改进:


This could also be logically improved:

If interpolation Then graphicsHandle.InterpolationMode = interpolation

graphicsHandle.InterpolationMode = interpolation



除了效率低下,第一个一个会导致错误,因为您将InterpolationMode与true / false进行比较,并且无法进行比较。



如果您尝试设置InterpolationMode一些东西,它已作为函数的参数传递,因为你已经设置,你可以只做上面的使用它;


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;

graphicsHandle.InterpolationMode = interpolation



你可能会感到困惑的是Optional关键字。这意味着你可以选择指定一个覆盖默认值的值,或者你可以保留它,并使用默认值。



这意味着你可以同时使用以下场景:


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:

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

Dim myImg As New Bitmap()
Dim img As Bitmap = EncodeImage(myImg, "this is the output", InterpolationMode.SomethingElse)


这篇关于如何从函数中获取interpolationmode值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆