C#代码转成java代码

将sgy文件转成png,C#的代码可以运行,希望懂C#和java的同志们帮忙转成java代码,感激不尽!

using System.Drawing;
using System.Text;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            byte[] MyData = new byte[0];
            //创建文件流的实例
            FileStream fileStream = new FileStream("D:\\environment\\idea\\json\\test-file\\sgy\\ss.sgy", FileMode.Open);
            BinaryReader binaryReader1 = new BinaryReader(fileStream);
            BinaryReader binaryReader2 = new BinaryReader(fileStream, Encoding.UTF8);
            BinaryReader binaryReader3 = new BinaryReader(fileStream, Encoding.UTF8, true);
            MyData = ReadHeadAndCreateImage(binaryReader3, 0, 1, 5, 20, 181, 185, 189, 193);
            MemoryStream ms = new MemoryStream(MyData);
            File.WriteAllBytes("D:\\environment\\idea\\json\\test-file\\sgy\\image.png", MyData);
            Console.WriteLine("图片写入完成!");
            Console.ReadKey();
        }

        /// 
        ///  读取二进制SEGY文件,并生成IMAGE反回二进制数据,segy定义
        /// 
        /// 
        /// 起始时间毫秒
        /// 
        /// 
        /// 
        /// 
        private static Byte[] ReadHeadAndCreateImage(BinaryReader reader, int startTime, float amplitude, int trace, int timeScaling, int HZB, int ZZB, int L, int T)
        {

            byte[] b = new byte[2];
            byte[] buffer;

            //跳过3600字节的卷头
            buffer = reader.ReadBytes(3600);

            b[0] = buffer[3217];
            b[1] = buffer[3216];

            int m_nTime = System.BitConverter.ToUInt16(b, 0);

            b[0] = buffer[3221];
            b[1] = buffer[3220];
            int m_nFrequency = BitConverter.ToUInt16(b, 0);


            b[0] = buffer[3225];
            b[1] = buffer[3224];
            int m_nCode = BitConverter.ToUInt16(b, 0);


            buffer = reader.ReadBytes(2);
            int m_nstartTrack = BitConverter.ToUInt16(buffer, 0);

            int m_nEndTrack;
            if (m_nCode.Equals(3))
            {
                m_nEndTrack = Convert.ToInt32((reader.BaseStream.Length - 3600) / (240 + m_nFrequency * 4));
            }
            else
            {
                m_nEndTrack = Convert.ToInt32((reader.BaseStream.Length - 3600) / (240 + m_nFrequency * 4));
            }

            //读算图形大小
            float LeftMargin = 3;    //左侧、右侧预留位置
            float TopMargin = 3;     //上侧预留位置

            float traceWidth = (m_nEndTrack - m_nstartTrack) * 1.0f / trace;     //总道宽度
            float traceHeight = ((m_nTime * m_nFrequency) / 1000000.0f) * timeScaling;   //道高度以少为单位计算,将微秒转为秒


            int imageWidth = MillimeterConvertPixel(traceWidth + LeftMargin * 2) * 10;   //计算的图形宽度
            int imageHeight = MillimeterConvertPixel(traceHeight + TopMargin) * 10;      //计算的图形高度

            float xstep = 10.0f / trace;     // X方向步长
            float ystep = (m_nTime * timeScaling * 10.0f) / 1000000;

            Console.WriteLine(imageWidth + ":" + imageHeight);

            Bitmap bitmap = new Bitmap(imageWidth, imageHeight);

            Graphics g = Graphics.FromImage(bitmap);
            g.PageUnit = GraphicsUnit.Millimeter;
            g.Clear(Color.White);


            #region 绘制地震剖面

            //当前填充
            List fill = new List();
            PointF SP = new PointF();
            PointF EP = new PointF();


            byte[] b4 = new byte[4];
            double value = 0;

            int X, Y;
            int L1 = 0;
            int T1 = 0;
            reader.BaseStream.Seek(3600, SeekOrigin.Begin);
            for (int i = 0; i < m_nEndTrack; i++)
            {
                //跳过240字节的道头
                buffer = reader.ReadBytes(240);

                if (L != -1)
                {
                    b4[0] = buffer[L + 2];
                    b4[1] = buffer[L + 1];
                    b4[2] = buffer[L];
                    b4[3] = buffer[L - 1];
                    L1 = BitConverter.ToInt32(b4, 0);
                }
                if (T != -1)
                {
                    b4[0] = buffer[T + 2];
                    b4[1] = buffer[T + 1];
                    b4[2] = buffer[T];
                    b4[3] = buffer[T - 1];
                    T1 = BitConverter.ToInt32(b4, 0);
                }
                b4[0] = buffer[HZB + 2];
                b4[1] = buffer[HZB + 1];
                b4[2] = buffer[HZB];
                b4[3] = buffer[HZB - 1];

                X = Convert.ToInt32(As_Traces(BitConverter.ToInt32(b4, 0).ToString(), 1));
                b4[0] = buffer[ZZB + 2];
                b4[1] = buffer[ZZB + 1];
                b4[2] = buffer[ZZB];
                b4[3] = buffer[ZZB - 1];
                Y = Convert.ToInt32(As_Traces(BitConverter.ToInt32(b4, 0).ToString(), 2));


                if (m_nCode.Equals(1))
                {

                    Console.WriteLine(Convert.ToInt32(reader.BaseStream.Length));
                    buffer = reader.ReadBytes(4 * m_nFrequency);
                    Console.WriteLine(Convert.ToInt32(reader.BaseStream.Length));

                    List values = new List();
                    for (int j = 0; j < buffer.Length; j = j + 4)
                    {
                        b4[3] = buffer[j + 0];
                        b4[2] = buffer[j + 1];
                        b4[1] = buffer[j + 2];
                        b4[0] = buffer[j + 3];

                        value = BitConverter.ToUInt32(b4, 0);

                        if (value != 0)
                        {
                            value = IBMtoIEE(BitConverter.ToUInt32(b4, 0));
                        }
                        values.Add(value);
                    }
                    double max = values.Max(xx => Math.Abs(xx));//计算最大幅度值                        
                    List pps = new List();      //绘图每道点列表

                    int index = 0;
                    int time = 0;
                    foreach (double d in values)
                    {
                        //将字符串转换为Float类型
                        float ppsX = Convert.ToSingle(LeftMargin * 10 + xstep * (i + 1) + xstep * (d / max) * amplitude);
                        float ppsY = TopMargin * 10 + index * ystep;
                        PointF pointF = new PointF(ppsX, ppsY);
                        pps.Add(pointF);

                        //计算时间刻度
                        time = ((m_nTime / 1000) * index) + startTime;
                        if (time % 500 == 0 && index > 0)
                        {
                            //左侧刻度线
                            g.DrawLine(new Pen(Color.Black, 1f), 20, TopMargin * 10 + index * ystep, 30, TopMargin * 10 + index * ystep);
                            //左侧文本
                            g.DrawString(time.ToString(), new Font("宋体", 15.0f), new SolidBrush(Color.Black), 1 * 10 - 1.5f, TopMargin * 10 + index * ystep - 3);
                            //右侧线
                            g.DrawLine(new Pen(Color.Black, 1f), traceWidth * 10 + LeftMargin * 10, TopMargin * 10 + index * ystep, traceWidth * 10 + LeftMargin * 10 + 10, TopMargin * 10 + index * ystep);
                            //右侧文本
                            g.DrawString(time.ToString(), new Font("宋体", 15.0f), new SolidBrush(Color.Black), traceWidth * 10 + LeftMargin * 10 + 10, TopMargin * 10 + index * ystep - 3);
                        }
                        else if (time % 100 == 0)
                        {
                            g.DrawLine(new Pen(Color.Black, 1f), 25, TopMargin * 10 + index * ystep, 30, TopMargin * 10 + index * ystep);
                            g.DrawLine(new Pen(Color.Black, 1f), traceWidth * 10 + LeftMargin * 10, TopMargin * 10 + index * ystep, traceWidth * 10 + LeftMargin * 10 + 5, TopMargin * 10 + index * ystep);
                        }

                        index++;
                    }

                    SP = new PointF(LeftMargin * 10 + xstep * (i + 1), 0);
                    EP = new PointF(LeftMargin * 10 + xstep * (i + 1), TopMargin * 10 + index * ystep);

                    //显示刻度线
                    if ((i + 1) % 10 == 0)
                    {
                        if ((i + 1) % 50 == 0)
                        {
                            g.DrawLine(new Pen(Color.Black, 1f), SP.X, 20, SP.X, 30);
                            if (L != -1)
                            {
                                g.DrawString("L" + L1, new Font("宋体", 14.0f), new SolidBrush(Color.Black), SP.X - 5, 10);
                            }
                            if (T != -1)
                            {
                                g.DrawString("T" + T1, new Font("宋体", 14.0f), new SolidBrush(Color.Black), SP.X - 5, 15);
                            }
                        }
                        else
                        {
                            g.DrawLine(new Pen(Color.Black, 1f), SP.X, 25, SP.X, 30);
                        }
                    }
                    //填充列表
                    List> FillList = new List>();
                    //填充
                    FillList.Clear();
                    bool SR = true;
                    PointF p1, p2;
                    fill = new List();

                    for (int s = 0; s < pps.Count - 1; s++)
                    {
                        p1 = pps[s];
                        p2 = pps[s + 1];
                        if (p1.X <= SP.X && p2.X > SP.X)
                        {
                            fill = new List();
                            PointF inter = new PointF();
                            GetIntersection(p1, p2, SP, EP, ref inter);
                            fill.Add(inter);
                            //添加交点与P2点
                            fill.Add(p2);
                            SR = true;
                        }
                        else if (p1.X > SP.X && p2.X > SP.X)
                        {
                            if (SR)
                            {
                                fill.Add(p1);
                                fill.Add(p2);
                            }
                        }
                        else if (p1.X > SP.X && p2.X <= SP.X)
                        {
                            if (SR)
                            {
                                //添加P1与交点
                                fill.Add(p1);
                                PointF inter = new PointF();
                                GetIntersection(p1, p2, SP, EP, ref inter);
                                fill.Add(inter);
                                FillList.Add(fill);
                                SR = false;
                            }
                        }
                        else if (p1.X == SP.X && p2.X == SP.X)
                        {
                            if (SR && s == pps.Count - 2)
                            {
                                FillList.Add(fill);
                            }
                        }
                        else if (p1.X < SP.X && p2.X < SP.X)
                        {
                            if (SR && s == pps.Count - 2)
                            {
                                FillList.Add(fill);
                            }
                        }
                        if (SR && s == pps.Count - 2)
                        {
                            FillList.Add(fill);
                        }

                    }

                    using (SolidBrush brush = new SolidBrush(Color.Black))
                    {
                        foreach (List px in FillList)
                        {
                            g.FillPolygon(brush, px.ToArray());
                            /*g.DrawPolygon(new Pen(Color.Black, 1f), px.ToArray());*/
                        }
                    }

                    g.DrawLines(new Pen(Color.Black, 0.0001f), pps.ToArray());

                }
                else if (m_nCode.Equals(2))
                {
                    buffer = reader.ReadBytes(4 * m_nFrequency);
                }
                else if (m_nCode.Equals(3))
                {
                    buffer = reader.ReadBytes(2 * m_nFrequency);
                }
                else if (m_nCode.Equals(4))
                {
                    buffer = reader.ReadBytes(4 * m_nFrequency);
                }

            }
            g.Dispose();
            //将Bitmap转为byte[]
            MemoryStream ms = new MemoryStream();
            // Save to memory using the Jpeg format
            bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            byte[] bmpBytes = ms.GetBuffer();
            bitmap.Dispose();
            ms.Close();
            return bmpBytes;
        }

        /// 
        /// 把毫米换算成像素
        /// 
        /// 多少毫米
        /// 多少像素
        public static int MillimeterConvertPixel(float Millimeter)
        {
            return ((int)(Millimeter / 25.4 * 96));
        }

        /// 
        /// 
        /// 
        /// 
        /// 
        /// 
        public static string As_Traces(string all, int type)
        {
            string as_traces = all;
            if (all.Length < 6) return all;
            if (type == 1)
            {

                if (all.Substring(0, 2) != "20") all = "20" + all;
                return all.Substring(0, 8);
            }
            if (type == 2)
            {
                if (all.Substring(0, 1) != "4") all = "4" + all;
                return all.Substring(0, 7);
            }
            return as_traces;
        }

        /// 
        /// 数值转换参数
        /// 
        /// 
        /// 
        private static double IBMtoIEE(UInt32 DataUint32)
        {
            //符号位
            int sign = (int)(DataUint32 >> 31);

            //7位指数
            // gain exponent from first byte, last 7 bits
            double exp0 = (double)((DataUint32 & 0x7f000000) >> 24);

            // 去除基数
            double exp = (double)(exp0 - 64);

            // gain mantissa from last 3 bytes 
            double frac = (double)(DataUint32 & 0x00ffffff);
            double fmant = frac / (Math.Pow(2, 24));

            return (1 - 2 * sign) * (Math.Pow(16, exp)) * fmant;
        }

        /// 
        /// 计算线段交点
        /// 
        /// 
        /// 
        /// 
        /// 
        /// 
        private static void GetIntersection(PointF a, PointF b, PointF c, PointF d, ref PointF intersection)
        {
            intersection.X = ((b.X - a.X) * (c.X - d.X) * (c.Y - a.Y) - c.X * (b.X - a.X) * (c.Y - d.Y) + a.X * (b.Y - a.Y) * (c.X - d.X)) / ((b.Y - a.Y) * (c.X - d.X) - (b.X - a.X) * (c.Y - d.Y));
            intersection.Y = ((b.Y - a.Y) * (c.Y - d.Y) * (c.X - a.X) - c.Y * (b.Y - a.Y) * (c.X - d.X) + a.Y * (b.X - a.X) * (c.Y - d.Y)) / ((b.X - a.X) * (c.Y - d.Y) - (b.Y - a.Y) * (c.X - d.X));
        }
        #endregion
    }

}

你可以百度

    private static Byte[] ReadHeadAndCreateImage(DataInputStream reader, int startTime, float amplitude, int trace, int timeScaling, int HZB, int ZZB, int L, int T) {
        try {
            byte[] b = new byte[2];
            int available = reader.available();

            // 跳过3600字节的卷头
            byte[] buffer = new byte[3600];
            int read01 = reader.read(buffer, 0, 3600);

            b[0] = buffer[3217];
            b[1] = buffer[3216];

            short m_nTime = BitConverter.toShort(b, 0);
            System.out.println("m_nTime:" + m_nTime);

            b[0] = buffer[3221];
            b[1] = buffer[3220];
            short m_nFrequency = BitConverter.toShort(b, 0);
            System.out.println("m_nFrequency:" + m_nFrequency);

            b[0] = buffer[3225];
            b[1] = buffer[3224];
            short m_nCode = BitConverter.toShort(b, 0);
            System.out.println("m_nCode:" + m_nCode);

            buffer = new byte[2];
            int read02 = reader.read(buffer, 0, 2);
            short m_nStartTrack = BitConverter.toShort(buffer, 0);
            System.out.println("m_nStartTrack:" + m_nStartTrack);

            int m_nEndTrack = (available - 3600) / (240 + m_nFrequency * 4);
            System.out.println("m_nEndTrack:" + m_nEndTrack);

            // 读算图形大小
            // 左侧、右侧预留位置
            float LeftMargin = 3;
            // 上侧预留位置
            float TopMargin = 3;
            // 总道宽度
            float traceWidth = (m_nEndTrack - m_nStartTrack) * 1.0f / trace;
            // 道高度以少为单位计算,将微秒转为秒
            float traceHeight = ((m_nTime * m_nFrequency) / 1000000.0f) * timeScaling;
            // 计算的图形宽度
            int imageWidth = MillimeterConvertPixel((traceWidth + LeftMargin * 2)) * 10;
            // 计算的图形高度
            int imageHeight = MillimeterConvertPixel((traceHeight + TopMargin)) * 10;
            System.out.println("图片宽度:" + imageWidth);
            System.out.println("图片高度:" + imageHeight);
            // X方向步长
            float xStep = (10.0f / trace);
            // Y方向步长
            float yStep = (m_nTime * timeScaling * 10.0f) / 1000000;
            System.out.println(xStep + ":" + yStep);

            // 对图片的操作
            // 获取图片缓冲区
            BufferedImage bufferedImage = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB);
            // 得到绘制坏境(这张图片的笔)
            Graphics2D graphics = bufferedImage.createGraphics();

            // 设置背景颜色
            graphics.setColor(Color.WHITE);
            // 填充整张图片(设置背景颜色)
            graphics.fillRect(0, 0, imageWidth, imageHeight);

            double value;
            int L1 = 0;
            int T1 = 0;
            byte[] b4 = new byte[4];
            long skip = reader.skip(2);

            for (int i = 0; i < m_nEndTrack; i++) {
                buffer = new byte[240];
                // 跳过240字节的道头
                int read03 = reader.read(buffer, 0, 240);
                if (L != -1) {
                    b4[0] = buffer[L + 2];
                    b4[1] = buffer[L + 1];
                    b4[2] = buffer[L];
                    b4[3] = buffer[L - 1];
                    L1 = BitConverter.toShort(b4, 0);
                }

                if (T != -1) {
                    b4[0] = buffer[T + 2];
                    b4[1] = buffer[T + 1];
                    b4[2] = buffer[T];
                    b4[3] = buffer[T - 1];
                    T1 = BitConverter.toShort(b4, 0);
                }

                b4[0] = buffer[HZB + 2];
                b4[1] = buffer[HZB + 1];
                b4[2] = buffer[HZB];
                b4[3] = buffer[HZB - 1];
                int integerX = BitConverter.toInt(b4, 0);
                String X = As_Traces(Integer.toString(integerX), 1);

                b4[0] = buffer[ZZB + 2];
                b4[1] = buffer[ZZB + 1];
                b4[2] = buffer[ZZB];
                b4[3] = buffer[ZZB - 1];
                int integerY = BitConverter.toInt(b4, 0);
                String Y = As_Traces(Integer.toString(integerY), 2);
                //todo 这里的values少一个
                if (m_nCode == 1) {
                    int m_nFrequency4 = 4 * m_nFrequency;
                    buffer = new byte[m_nFrequency4];
                    int read04 = reader.read(buffer);
                    List<Double> values = new ArrayList<>();
                    for (int j = 0; j < buffer.length; j = (j + 4)) {
                        b4[3] = buffer[j];
                        b4[2] = buffer[j + 1];
                        b4[1] = buffer[j + 2];
                        b4[0] = buffer[j + 3];
                        value = BitConverter.toLong(b4, 0);
                        if (value != 0) {
                            value = IBMtoIEE(BitConverter.toLong(b4, 0));
                        }
                        values.add(value);
                    }
                    // 计算最大幅度值
                    double max = values.stream().reduce(Math.abs(values.get(0)), Double::max);
                    // 绘图
                    int time;
                    int index = 0;
                    // 字体样式 字体格式 字体大小
                    graphics.setFont(new Font("宋体", Font.PLAIN, 20));
                    // 设置字体颜色
                    graphics.setColor(Color.BLACK);

                    // 每道点列表
                    List<Point2D> pps = new ArrayList<>();
                    for (double d : values) {
                        float x = (float) (LeftMargin * 10 + xStep * (i + 1) + xStep * (d / max) * amplitude);
                        float y = (TopMargin * 10 + index * yStep);
                        Point2D point = new Point2D(x, y);
                        pps.add(point);
                        // 计算时间刻度
                        time = ((m_nTime / 1000) * index) + startTime;
                        if (time % 500 == 0 && index > 0) {
                            int y1 = (int) (TopMargin * 10 + index * yStep - 3);
                            // 左侧刻度线
                            graphics.drawLine(MillimeterConvertPixel(20), MillimeterConvertPixel((int) (TopMargin * 10 + index * yStep)), MillimeterConvertPixel(30), MillimeterConvertPixel((int) (TopMargin * 10 + index * yStep)));
                            // 左侧文本
                            graphics.drawString(Integer.toString(time), MillimeterConvertPixel((int) (10 - 1.5f)), MillimeterConvertPixel(y1));
                            // 右侧线
                            graphics.drawLine(MillimeterConvertPixel((int) (traceWidth * 10 + LeftMargin * 10)), MillimeterConvertPixel((int) (TopMargin * 10 + index * yStep)), MillimeterConvertPixel((int) (traceWidth * 10 + LeftMargin * 10 + 10)), MillimeterConvertPixel((int) (TopMargin * 10 + index * yStep)));
                            // 右侧文本
                            graphics.drawString(Integer.toString(time), MillimeterConvertPixel((int) (traceWidth * 10 + LeftMargin * 10 + 10)), MillimeterConvertPixel(y1));
                        } else if (time % 100 == 0) {
                            graphics.drawLine(MillimeterConvertPixel(25), MillimeterConvertPixel((int) (TopMargin * 10 + index * yStep)), MillimeterConvertPixel(30), MillimeterConvertPixel((int) (TopMargin * 10 + index * yStep)));
                            graphics.drawLine(MillimeterConvertPixel((int) (traceWidth * 10 + LeftMargin * 10)), MillimeterConvertPixel((int) (TopMargin * 10 + index * yStep)), MillimeterConvertPixel((int) (traceWidth * 10 + LeftMargin * 10 + 5)), MillimeterConvertPixel((int) (TopMargin * 10 + index * yStep)));
                        }
                        index++;
                    }
                    Point2D SP = new Point2D(((LeftMargin * 10 + xStep * (i + 1))), 0);
                    Point2D EP = new Point2D(((LeftMargin * 10 + xStep * (i + 1))), MillimeterConvertPixel((TopMargin * 10 + index * yStep)));
                    // 显示刻度线
                    if ((i + 1) % 10 == 0) {
                        if ((i + 1) % 50 == 0) {
                            graphics.drawLine(MillimeterConvertPixel(SP.x), MillimeterConvertPixel(20), MillimeterConvertPixel(SP.x), MillimeterConvertPixel(30));
                            if (L != -1) {
                                graphics.drawString("L" + L1, (MillimeterConvertPixel(SP.x - (5))), MillimeterConvertPixel(10));
                            }
                            if (T != -1) {
                                graphics.drawString("T" + T1, (MillimeterConvertPixel(SP.x - (5))), MillimeterConvertPixel(18));
                            }
                        } else {
                            graphics.drawLine(MillimeterConvertPixel(SP.x), MillimeterConvertPixel(25), MillimeterConvertPixel(SP.x), MillimeterConvertPixel(30));
                        }
                    }
                    Point2D p1, p2;
                    boolean SR = true;
                    // 填充列表
                    List<List<Point2D>> fillLists = new ArrayList<>();
                    // 当前填充
                    List<Point2D> fills = new ArrayList<>();
                    for (int s = 0; s < pps.size() - 1; s++) {
                        p1 = pps.get(s);
                        p2 = pps.get(s + 1);
                        if (p1.x <= SP.x && p2.x > SP.x) {
                            fills = new ArrayList<>();
                            // 获取交点
                            Point2D inter = GetIntersection(p1, p2, SP, EP);
                            fills.add(inter);
                            // 添加交点与P2点
                            fills.add(p2);
                            SR = true;
                        } else if (p1.x > SP.x && p2.x > SP.x) {
                            if (SR) {
                                fills.add(p1);
                                fills.add(p2);
                            }
                        } else if (p1.x > SP.x && p2.x <= SP.x) {
                            if (SR) {
                                // 添加P1与交点
                                fills.add(p1);
                                Point2D inter = GetIntersection(p1, p2, SP, EP);
                                fills.add(inter);
                                fillLists.add(fills);
                                SR = false;
                            }
                        } else if (p1.x == SP.x && p2.x == SP.x) {
                            if (SR && s == pps.size() - 2) {
                                fillLists.add(fills);
                            }
                        } else if (p1.x < SP.x && p2.x < SP.x) {
                            if (SR && s == pps.size() - 2) {
                                fillLists.add(fills);
                            }
                        }
                        if (SR && s == pps.size() - 2) {
                            fillLists.add(fills);
                        }
                    }

                    // 多边形 fillLists(数据相同)
                    Polygon polygon = new Polygon();
                    for (List<Point2D> points : fillLists) {
                        for (Point2D point : points) {
                            polygon.addPoint(MillimeterConvertPixel(point.x), MillimeterConvertPixel(point.y));
                        }
                    }
                    // 填充多边形
                    graphics.fillPolygon(polygon);
                    graphics.drawPolygon(polygon);
                    // 画曲线
                    for (int i1 = 0; i1 < pps.size(); i1++) {
                        if (i1 + 1 < pps.size()) {
                            Point2D point2D = pps.get(i1);
                            Point2D point2D1 = pps.get(i1 + 1);
                            graphics.drawLine(MillimeterConvertPixel(point2D.x), MillimeterConvertPixel(point2D.y), MillimeterConvertPixel(point2D1.x), MillimeterConvertPixel(point2D1.y));
                        }
                    }
                } else if (m_nCode == 2) {
                    int m_nFrequency4 = m_nFrequency * 4;
                    buffer = new byte[m_nFrequency4];
                    int read05 = reader.read(buffer, 0, m_nFrequency4);
                } else if (m_nCode == 3) {
                    int m_nFrequency2 = m_nFrequency * 2;
                    buffer = new byte[m_nFrequency2];
                    int read06 = reader.read(buffer, 0, m_nFrequency2);
                } else if (m_nCode == 4) {
                    int m_nFrequency4 = m_nFrequency * 4;
                    buffer = new byte[m_nFrequency4];
                    int read07 = reader.read(buffer, 0, m_nFrequency4);
                }
            }
            graphics.dispose();
            // 输出到文件流
            ImageIO.write(bufferedImage, "PNG", new FileOutputStream("D:\\environment\\idea\\json\\test-file\\sgy\\srcImageFile.png"));
            System.out.println("图片写入完成!");
            System.out.println("D:\\environment\\idea\\json\\test-file\\sgy\\srcImageFile.png");
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }


小魔女参考了bing和GPT部分内容调写:
使用Java将sgy文件转换成png文件,可以使用Java的IO流进行读取文件,然后使用Java的ImageIO类进行图片的转换。

首先,使用FileInputStream读取sgy文件,然后使用BufferedInputStream进行缓冲:

FileInputStream fis = new FileInputStream("sgy文件路径");
BufferedInputStream bis = new BufferedInputStream(fis);

接着,使用ImageIO类的write方法将读取到的文件转换为png格式:

ImageIO.write(bis, "png", new File("png文件路径"));

最后,关闭流:

bis.close();
fis.close();

回答不易,记得采纳呀。

参考GPT和自己的转换工具,代码如下:

package consoleapp1;

import java.io.*;

public class Program
{
    public static void main(String[] args)
    {
//VB TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: Dim MyData As Byte() = New Byte(-1) {}
        byte[] MyData = new byte[0];
        FileInputStream fileStream = new FileInputStream("D:\\environment\\idea\\json\\test-file\\sgy\\ss.sgy");
        BinaryReader binaryReader1 = new BinaryReader(fileStream);
        BinaryReader binaryReader2 = new BinaryReader(fileStream, Encoding.UTF8);
        BinaryReader binaryReader3 = new BinaryReader(fileStream, Encoding.UTF8, true);
        MyData = ReadHeadAndCreateImage(binaryReader3, 0, 1, 5, 20, 181, 185, 189, 193);
//VB TO JAVA CONVERTER TODO TASK: VB to Java Converter cannot determine whether this System.IO.MemoryStream is input or output:
        MemoryStream ms = new MemoryStream(MyData);
        File.WriteAllBytes("D:\\environment\\idea\\json\\test-file\\sgy\\image.png", MyData);
        System.out.println("图片写入完成!");
        Console.ReadKey();
    }

private static byte[] ReadHeadAndCreateImage(BinaryReader reader, int startTime, float amplitude, int trace, int timeScaling, int HZB, int ZZB, int L, int T)
{
byte[] b = new byte[2];
//VB TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: Dim buffer As Byte()
            byte[] buffer;
            buffer = reader.ReadBytes(3600);
            b[0] = buffer[3217];
            b[1] = buffer[3216];
            int m_nTime = System.BitConverter.ToUInt16(b, 0);
            b[0] = buffer[3221];
            b[1] = buffer[3220];
            int m_nFrequency = BitConverter.ToUInt16(b, 0);
            b[0] = buffer[3225];
            b[1] = buffer[3224];
            int m_nCode = BitConverter.ToUInt16(b, 0);
            buffer = reader.ReadBytes(2);
            int m_nstartTrack = BitConverter.ToUInt16(buffer, 0);
            int m_nEndTrack = 0;

            if ((new Integer(m_nCode)).equals(3))
            {
                m_nEndTrack = FloatingPointToInteger.ToInt32((reader.BaseStream.Length - 3600) / (double)(240 + m_nFrequency * 4));
            }
            else
            {
                m_nEndTrack = FloatingPointToInteger.ToInt32((reader.BaseStream.Length - 3600) / (double)(240 + m_nFrequency * 4));
            }

//Helper class added by VB to Java Converter:

package tangible;

//----------------------------------------------------------------------------------------
//    Copyright © 2007 - 2021 Tangible Software Solutions, Inc.
//    This class can be used by anyone provided that the copyright notice remains intact.
//
//    This class is used to convert System.Convert methods which convert from
//    floating point types to integral types.
//----------------------------------------------------------------------------------------
public final class FloatingPointToInteger
{
    public static byte ToSByte(double source)
    {
        byte floor = (byte)Math.floor(source);
        if (Math.abs(source - floor) == 0.5)
        {
            if (floor % 2 == 0)
                return floor;
            else
                return (byte)Math.ceil(source);
        }
        else if (Math.abs(source - floor) < 0.5)
            return floor;
        else
            return (byte)Math.ceil(source);
    }

    public static short ToInt16(double source)
    {
        short floor = (short)Math.floor(source);
        if (Math.abs(source - floor) == 0.5)
        {
            if (floor % 2 == 0)
                return floor;
            else
                return (short)Math.ceil(source);
        }
        else if (Math.abs(source - floor) < 0.5)
            return floor;
        else
            return (short)Math.ceil(source);
    }

    public static int ToInt32(double source)
    {
        int floor = (int)Math.floor(source);
        if (Math.abs(source - floor) == 0.5)
        {
            if (floor % 2 == 0)
                return floor;
            else
                return (int)Math.ceil(source);
        }
        else if (Math.abs(source - floor) < 0.5)
            return floor;
        else
            return (int)Math.ceil(source);
    }

    public static long ToInt64(double source)
    {
        long floor = (long)Math.floor(source);
        if (Math.abs(source - floor) == 0.5)
        {
            if (floor % 2 == 0)
                return floor;
            else
                return (long)Math.ceil(source);
        }
        else if (Math.abs(source - floor) < 0.5)
            return floor;
        else
            return (long)Math.ceil(source);
    }
}
float LeftMargin = 3;
            float TopMargin = 3;
            float traceWidth = (m_nEndTrack - m_nstartTrack) * 1.0F / trace;
            float traceHeight = ((m_nTime * m_nFrequency) / 1000000.0F) * timeScaling;
            int imageWidth = MillimeterConvertPixel(traceWidth + LeftMargin * 2) * 10;
            int imageHeight = MillimeterConvertPixel(traceHeight + TopMargin) * 10;
            float xstep = 10.0F / trace;
            float ystep = (m_nTime * timeScaling * 10.0F) / 1000000;
            System.out.println(imageWidth + ":" + imageHeight);
            Bitmap bitmap = new Bitmap(imageWidth, imageHeight);
            Graphics g = Graphics.FromImage(bitmap);
            g.PageUnit = GraphicsUnit.Millimeter;
            g.Clear(Color.White);
            ArrayList<PointF> fill = new ArrayList<PointF>();
            PointF SP = new PointF();
            PointF EP = new PointF();
//VB TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: Dim b4 As Byte() = New Byte(3) {}
            byte[] b4 = new byte[4];
            double value = 0;
            int X = 0;
            int Y = 0;
            int L1 = 0;
            int T1 = 0;
            reader.BaseStream.Seek(3600, SeekOrigin.Begin);
for (int i = 0; i < m_nEndTrack; i++)
{
                buffer = reader.ReadBytes(240);

                if (L != -1)
                {
                    b4(0) = buffer(L + 2);
                    b4(1) = buffer(L + 1);
                    b4(2) = buffer(L);
                    b4(3) = buffer(L - 1);
                    L1 = BitConverter.ToInt32(b4, 0);
                }

                if (T != -1)
                {
                    b4(0) = buffer(T + 2);
                    b4(1) = buffer(T + 1);
                    b4(2) = buffer(T);
                    b4(3) = buffer(T - 1);
                    T1 = BitConverter.ToInt32(b4, 0);
                }

                b4(0) = buffer(HZB + 2);
                b4(1) = buffer(HZB + 1);
                b4(2) = buffer(HZB);
                b4(3) = buffer(HZB - 1);
                X = (int)As_Traces(String.valueOf(BitConverter.ToInt32(b4, 0)), 1);
                b4(0) = buffer(ZZB + 2);
                b4(1) = buffer(ZZB + 1);
                b4(2) = buffer(ZZB);
                b4(3) = buffer(ZZB - 1);
                Y = (int)As_Traces(String.valueOf(BitConverter.ToInt32(b4, 0)), 2);
if (m_nCode.equals(1))
{
                    System.out.println((int)reader.BaseStream.Length);
                    buffer = reader.ReadBytes(4 * m_nFrequency);
                    System.out.println((int)reader.BaseStream.Length);
                    ArrayList<Double> values = new ArrayList<Double>();
                    int j = 0;

                    while (j < buffer.Length)
                    {
                        b4(3) = buffer(j + 0);
                        b4(2) = buffer(j + 1);
                        b4(1) = buffer(j + 2);
                        b4(0) = buffer(j + 3);
                        value = BitConverter.ToUInt32(b4, 0);

                        if (value != 0)
                        {
                            value = IBMtoIEE(BitConverter.ToUInt32(b4, 0));
                        }

                        values.add(value);
                        j = j + 4;
                    }
double max = values.Max((xx) -> Math.abs(xx));
                    ArrayList<PointF> pps = new ArrayList<PointF>();
                    int index = 0;
                    int time = 0;

                    for (double d : values)
                    {
                        float ppsX = (float)(LeftMargin * 10 + xstep * (i + 1) + xstep * (d / max) * amplitude);
                        float ppsY = TopMargin * 10 + index * ystep;
                        PointF pointF = new PointF(ppsX, ppsY);
                        pps.add(pointF);
                        time = ((m_nTime / 1000) * index) + startTime;

                        if (time % 500 == 0 && index > 0)
                        {
                            g.DrawLine(new Pen(Color.Black, 1.0F), 20, TopMargin * 10 + index * ystep, 30, TopMargin * 10 + index * ystep);
                            g.DrawString(String.valueOf(time), new Font("宋体", 15.0F), new SolidBrush(Color.Black), 1 * 10 - 1.5F, TopMargin * 10 + index * ystep - 3);
                            g.DrawLine(new Pen(Color.Black, 1.0F), traceWidth * 10 + LeftMargin * 10, TopMargin * 10 + index * ystep, traceWidth * 10 + LeftMargin * 10 + 10, TopMargin * 10 + index * ystep);
                            g.DrawString(String.valueOf(time), new Font("宋体", 15.0F), new SolidBrush(Color.Black), traceWidth * 10 + LeftMargin * 10 + 10, TopMargin * 10 + index * ystep - 3);
                        }
                        else if (time % 100 == 0)
                        {
                            g.DrawLine(new Pen(Color.Black, 1.0F), 25, TopMargin * 10 + index * ystep, 30, TopMargin * 10 + index * ystep);
                            g.DrawLine(new Pen(Color.Black, 1.0F), traceWidth * 10 + LeftMargin * 10, TopMargin * 10 + index * ystep, traceWidth * 10 + LeftMargin * 10 + 5, TopMargin * 10 + index * ystep);
                        }

                        index += 1;
                    }
SP = new PointF(LeftMargin * 10 + xstep * (i + 1), 0);
                    EP = new PointF(LeftMargin * 10 + xstep * (i + 1), TopMargin * 10 + index * ystep);

                    if ((i + 1) % 10 == 0)
                    {

                        if ((i + 1) % 50 == 0)
                        {
                            g.DrawLine(new Pen(Color.Black, 1.0F), SP.X, 20, SP.X, 30);

                            if (L != -1)
                            {
                                g.DrawString("L" + L1, new Font("宋体", 14.0F), new SolidBrush(Color.Black), SP.X - 5, 10);
                            }

                            if (T != -1)
                            {
                                g.DrawString("T" + T1, new Font("宋体", 14.0F), new SolidBrush(Color.Black), SP.X - 5, 15);
                            }
                        }
                        else
                        {
                            g.DrawLine(new Pen(Color.Black, 1.0F), SP.X, 25, SP.X, 30);
                        }
                    }

                    ArrayList<ArrayList<PointF>> FillList = new ArrayList<ArrayList<PointF>>();
                    FillList.clear();
                    boolean SR = true;
                    PointF p1 = new PointF();
                    PointF p2 = new PointF();
                    fill = new ArrayList<PointF>();
for (int s = 0; s < pps.Count - 1; s++)
{
                        p1 = pps(s);
                        p2 = pps(s + 1);

                        if (p1.X <= SP.X && p2.X > SP.X)
                        {
                            fill = new ArrayList<PointF>();
                            PointF inter = new PointF();
                            GetIntersection(p1, p2, SP, EP, inter);
                            fill.Add(inter);
                            fill.Add(p2);
                            SR = true;
                        }
                        else if (p1.X > SP.X && p2.X > SP.X)
                        {

                            if (SR)
                            {
                                fill.Add(p1);
                                fill.Add(p2);
                            }
                        }
                        else if (p1.X > SP.X && p2.X <= SP.X)
                        {

                            if (SR)
                            {
                                fill.Add(p1);
                                PointF inter = new PointF();
                                GetIntersection(p1, p2, SP, EP, inter);
                                fill.Add(inter);
                                FillList.Add(fill);
                                SR = false;
                            }
                        }
                        else if (p1.X == SP.X && p2.X == SP.X)
                        {

                            if (SR && s == pps.Count - 2)
                            {
                                FillList.Add(fill);
                            }
}
else if (p1.X < SP.X && p2.X < SP.X)
{

                            if (SR && s == pps.Count - 2)
                            {
                                FillList.Add(fill);
                            }
                        }

                        if (SR && s == pps.Count - 2)
                        {
                            FillList.Add(fill);
                        }
//VB TO JAVA CONVERTER TODO TASK: The following line could not be converted:
                    Next

                    try (SolidBrush brush = new SolidBrush(Color.Black))
                    {

                        for (ArrayList<PointF> px : FillList)
                        {
                            g.FillPolygon(brush, px.toArray(new PointF[0]));
                        }
                    }

                    g.DrawLines(new Pen(Color.Black, 0.0001F), pps.ToArray());
                }
                else if (m_nCode.equals(2))
                {
                    buffer = reader.ReadBytes(4 * m_nFrequency);
                }
                else if (m_nCode.equals(3))
                {
                    buffer = reader.ReadBytes(2 * m_nFrequency);
                }
                else if (m_nCode.equals(4))
                {
                    buffer = reader.ReadBytes(4 * m_nFrequency);
                }
//VB TO JAVA CONVERTER TODO TASK: The following line could not be converted:
            Next
g.Dispose();
//VB TO JAVA CONVERTER TODO TASK: VB to Java Converter cannot determine whether this System.IO.MemoryStream is input or output:
            MemoryStream ms = new MemoryStream();
            bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
//VB TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: Dim bmpBytes As Byte() = ms.GetBuffer()
            byte[] bmpBytes = ms.GetBuffer();
            bitmap.Dispose();
            ms.Close();
            return bmpBytes;
        }

        public static int MillimeterConvertPixel(float Millimeter)
        {
            return (FloatingPointToInteger.ToInt32((Millimeter / 25.4 * 96)));
        }

        public static String As_Traces(String all, int type)
        {
            String tempAs_Traces = null;
            String tempAs_Traces = all;
            if (all.length() < 6)
            {
                return all;
            }

            if (type == 1)
            {
                if (!all.substring(0, 2).equals("20"))
                {
                    all = "20" + all;
                }
                return all.substring(0, 8);
            }

            if (type == 2)
            {
                if (!all.substring(0, 1).equals("4"))
                {
                    all = "4" + all;
                }
                return all.substring(0, 7);
            }

            return tempAs_Traces;
        }

//Helper class added by VB to Java Converter:

package tangible;

//----------------------------------------------------------------------------------------
//    Copyright © 2007 - 2021 Tangible Software Solutions, Inc.
//    This class can be used by anyone provided that the copyright notice remains intact.
//
//    This class is used to convert System.Convert methods which convert from
//    floating point types to integral types.
//----------------------------------------------------------------------------------------
public final class FloatingPointToInteger
{
    public static byte ToSByte(double source)
    {
        byte floor = (byte)Math.floor(source);
        if (Math.abs(source - floor) == 0.5)
        {
            if (floor % 2 == 0)
                return floor;
            else
                return (byte)Math.ceil(source);
        }
        else if (Math.abs(source - floor) < 0.5)
            return floor;
        else
            return (byte)Math.ceil(source);
    }

    public static short ToInt16(double source)
    {
        short floor = (short)Math.floor(source);
        if (Math.abs(source - floor) == 0.5)
        {
            if (floor % 2 == 0)
                return floor;
            else
                return (short)Math.ceil(source);
        }
        else if (Math.abs(source - floor) < 0.5)
            return floor;
        else
            return (short)Math.ceil(source);
    }

    public static int ToInt32(double source)
    {
        int floor = (int)Math.floor(source);
        if (Math.abs(source - floor) == 0.5)
        {
            if (floor % 2 == 0)
                return floor;
            else
                return (int)Math.ceil(source);
        }
        else if (Math.abs(source - floor) < 0.5)
            return floor;
        else
            return (int)Math.ceil(source);
    }

    public static long ToInt64(double source)
    {
        long floor = (long)Math.floor(source);
        if (Math.abs(source - floor) == 0.5)
        {
            if (floor % 2 == 0)
                return floor;
            else
                return (long)Math.ceil(source);
        }
        else if (Math.abs(source - floor) < 0.5)
            return floor;
        else
            return (long)Math.ceil(source);
    }
}
private static double IBMtoIEE(int DataUint32)
{
//VB TO JAVA CONVERTER WARNING: The right shift operator was replaced by Java's logical right shift operator since the left operand was originally of an unsigned type, but you should confirm this replacement:
Int sign = (Int())(DataUint32 >>> 31);
// gain exponent from first Byte, last 7 bits
//VB TO JAVA CONVERTER WARNING: The right shift operator was not replaced by Java's logical right shift operator since the left operand was not confirmed to be of an unsigned type, but you should review whether the logical right shift operator (>>>) is more appropriate:
            double exp0 = (double)((DataUint32 + String.valueOf(0x7f000000)) >> 24);

/** 
*/
            double exp = (double)(exp0 - 64);
            double frac = (double)(DataUint32 & 0xFFFFFF);
            double fmant = frac / (Math.pow(2, 24));
            return (1 - 2 * sign) * (Math.pow(16, exp)) * fmant;
        }

        private static void GetIntersection(PointF a, PointF b, PointF c, PointF d, tangible.RefObject<PointF> intersection)
        {
            intersection.refArgValue.X = ((b.X - a.X) * (c.X - d.X) * (c.Y - a.Y) - c.X * (b.X - a.X) * (c.Y - d.Y) + a.X * (b.Y - a.Y) * (c.X - d.X)) / ((b.Y - a.Y) * (c.X - d.X) - (b.X - a.X) * (c.Y - d.Y));
            intersection.refArgValue.Y = ((b.Y - a.Y) * (c.Y - d.Y) * (c.X - a.X) - c.Y * (b.Y - a.Y) * (c.X - d.X) + a.Y * (b.X - a.X) * (c.Y - d.Y)) / ((b.X - a.X) * (c.Y - d.Y) - (b.Y - a.Y) * (c.X - d.X));
        }
    }

//Helper class added by VB to Java Converter:

package tangible;

//----------------------------------------------------------------------------------------
//    Copyright © 2007 - 2021 Tangible Software Solutions, Inc.
//    This class can be used by anyone provided that the copyright notice remains intact.
//
//    This class is used to replicate the ability to pass arguments by reference in Java.
//----------------------------------------------------------------------------------------
public final class RefObject<T>
{
    public T refArgValue;
    public RefObject(T refArg)
    {
        refArgValue = refArg;
    }
}

可以参考下面的代码
需要引用的jar
batik-all-1.7.jar
xml-apis-ext.jar


    /**
     * 将svg字符串转换为png
     *
     * @param svgCode svg代码
     * @param pngFilePath 保存的路径
     * @throws TranscoderException svg代码异常
     * @throws IOException io错误
     */
    public static void convertToPng(String svgCode, String pngFilePath) throws IOException,
            TranscoderException {
 
        File file = new File(pngFilePath);
 
        FileOutputStream outputStream = null;
        try {
            file.createNewFile();
            outputStream = new FileOutputStream(file);
            convertToPng(svgCode, outputStream);
        } finally {
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
 
    /**
     * 将svgCode转换成png文件,直接输出到流中
     *
     * @param svgCode svg代码
     * @param outputStream 输出流
     * @throws TranscoderException 异常
     * @throws IOException io异常
     */
    public static void convertToPng(String svgCode, OutputStream outputStream)
            throws TranscoderException, IOException {
        try {
            byte[] bytes = svgCode.getBytes("utf-8");
            PNGTranscoder t = new PNGTranscoder();
            TranscoderInput input = new TranscoderInput(new ByteArrayInputStream(bytes));
            TranscoderOutput output = new TranscoderOutput(outputStream);
            t.transcode(input, output);
            outputStream.flush();
        } finally {
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

你可以参考 C# 代码的逻辑和功能,手动编写对应的 Java 代码。以下是一些可能有用的技巧:

C# 中的类可以转换为 Java 中的类,但是语法略有不同。例如,C# 中的类定义如下:

plaintext
Copy code
public class MyClass {
    public int MyProperty { get; set; }
    public void MyMethod() {
        // do something
    }
}


Java 中的类定义如下:

plaintext
Copy code
public class MyClass {
    private int myProperty;
    public int getMyProperty() {
        return myProperty;
    }
    public void setMyProperty(int value) {
        myProperty = value;
    }
    public void myMethod() {
        // do something
    }
}

注意,Java 中使用 getter 和 setter 方法来访问和修改属性值。
2. C# 中的控制语句和 Java 中的控制语句很相似,可以直接进行转换。例如,C# 中的 if 语句:

plaintext
Copy code
if (x > 0) {
    Console.WriteLine("x is positive");
}
else {
    Console.WriteLine("x is zero or negative");
}

Java 中的 if 语句:

plaintext
Copy code
if (x > 0) {
    System.out.println("x is positive");
}
else {
    System.out.println("x is zero or negative");
}


C# 中的循环语句和 Java 中的循环语句也很相似,可以直接进行转换。例如,C# 中的 for 循环语句:

plaintext
Copy code
for (int i = 0; i < 10; i++) {
    Console.WriteLine(i);
}

Java 中的 for 循环语句:

plaintext
Copy code
for (int i = 0; i < 10; i++) {
    System.out.println(i);
}

C# 中的异常处理和 Java 中的异常处理也很相似,可以直接进行转换。例如,C# 中的 try-catch 语句:


plaintext
Copy code
try {
    // do something
}
catch (Exception ex) {
    Console.WriteLine("An error occurred: " + ex.Message);
}


Java 中的 try-catch 语句:


plaintext
Copy code
try {
    // do something
}
catch (Exception ex) {
    System.out.println("An error occurred: " + ex.getMessage());
}


希望这些技巧可以帮助你将 C# 代码转换为 Java 代码。

以下答案由GPT-3.5大模型与博主波罗歌共同编写:
以下是Java版的代码:

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Polygon;
import java.awt.geom.Point2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.ShortBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.imageio.ImageIO;

public class Conversion {

public static void main(String[] args) {
    byte[] MyData = new byte[0];
    // 创建文件流的实例
    InputStream inputStream = null;
    try {
        inputStream = new FileInputStream(new File("D:\\environment\\idea\\json\\test-file\\sgy\\ss.sgy"));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    ByteBuffer buffer = ByteBuffer.allocate(3600

如果我的回答解决了您的问题,请采纳!