BufferedImage 从 Java 到 C# 的等价物

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4776939/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 07:58:30  来源:igfitidea点击:

Equivalent of BufferedImage from Java to C#

c#java.netsyntax

提问by Bosco

I am trying to convert a Java program to C# and I don't know the equivalent of BufferedImage from Java to C#...

我正在尝试将 Java 程序转换为 C#,但我不知道 BufferedImage 从 Java 到 C# 的等效项...

Code from Java:

来自Java的代码:

public static String ActiveContour(int x11, int x22, int y11, int y22, BufferedImage bufIm, int contor)
{

double [][] img=new double[bufIm.getHeight()][bufIm.getWidth()];
double [][] imgf=new double[bufIm.getHeight()][bufIm.getWidth()];

w=bufIm.getWidth();
h=bufIm.getHeight();

for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
    {
       img[i][j]=bufIm.getRGB(j, i);
       c = new Color((int)img[i][j]);
       img[i][j]= 0.2898*c.getRed() + 0.5870*c.getGreen() + 0.1140*c.getBlue(); 
    }

Am I missing a statement?

我错过了一个声明吗?

using System...;

because in Java I have

因为在 Java 中我有

import java.awt.image.BufferedImage;

回答by gbvb

System.Drawing.Bitmapis the closest I can think of.

System.Drawing.Bitmap是我能想到的最接近的。

回答by Arjang

What does this function do? Why bother with translating the code bit by bit when most probably there is another way achieving the same result using C# classes? In C# using System.Drawing.Bitmap is common practice but there are other ways depending on what the code is meant to be doing.

这个函数有什么作用?当很可能有另一种使用 C# 类实现相同结果的方法时,为什么还要一点一点地翻译代码呢?在 C# 中,使用 System.Drawing.Bitmap 是常见的做法,但根据代码的意图,还有其他方法。