intecn 2016-06-28 09:59 采纳率: 0%
浏览 1885

代码转换 Java转CSharp

有哪位大神帮忙把下面的java代码转换成C#
import java.awt.*;
import javax.swing.*;
import java.awt.image.*;
import java.awt.color.*;

public class GreyFrame extends JComponent
{
private int width;
private int height;
private Dimension size;
private BufferedImage image;
private String title;

public GreyFrame(int width, int height, byte[] data)
{
    this(width, height, data, null);
}

public GreyFrame(int width, int height, byte[] data, String title)
{
    this.width = width;
    this.height = height;
    this.title = title;
    size = new Dimension(width, height);

    DataBufferByte dataBuffer = new DataBufferByte(data, data.length, 0);

    PixelInterleavedSampleModel sampleModel = new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE, width, height, 1, width, new int[] {0});
    ColorSpace colourSpace = ColorSpace.getInstance(ColorSpace.CS_GRAY);
    ComponentColorModel colourModel = new ComponentColorModel(colourSpace, new int[] {8}, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);

    WritableRaster raster = Raster.createWritableRaster(sampleModel, dataBuffer, null);

    image = new BufferedImage(colourModel, raster, false, null);
}

public Graphics2D getBufferImageGraphics()
{
    return image.createGraphics();
}

public BufferedImage getBufferImage()
{
    return image;
}

public Dimension getSize()
{
    return size;
}

public Dimension getPreferredSize()
{
    return size;
}

public void paint(Graphics g)
{
    super.paint(g);
    if (image != null) g.drawImage(image, 0, 0, this);

    if (title != null) {
        g.setColor(Color.RED);
        g.drawString(title, 5, height - 5);
    }
}

}

  • 写回答

1条回答 默认 最新

  • threenewbee 2016-06-28 16:13
    关注

    这代码主要是从字节中得到图像,然后绘制图像和红色的文字水印。你按照这个思路去写下就是了。

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!