Azure++ 2023-03-02 17:23 采纳率: 33.3%
浏览 112
已结题

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定义
        /// 
        /// <param name="reader"></param>
        /// <param name="startTime">起始时间毫秒</param>
        /// <param name="amplitude"></param>
        /// <param name="trace"></param>
        /// <param name="timeScaling"></param>
        /// <returns></returns>
        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<PointF> fill = new List<PointF>();
            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<double> values = new List<double>();
                    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<PointF> pps = new List<PointF>();      //绘图每道点列表

                    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<List<PointF>> FillList = new List<List<PointF>>();
                    //填充
                    FillList.Clear();
                    bool SR = true;
                    PointF p1, p2;
                    fill = new List<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 List<PointF>();
                            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<PointF> 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;
        }

        /// 
        /// 把毫米换算成像素
        /// 
        /// <param name="Millimeter">多少毫米</param>
        /// <returns>多少像素</returns>
        public static int MillimeterConvertPixel(float Millimeter)
        {
            return ((int)(Millimeter / 25.4 * 96));
        }

        /// 
        /// 
        /// 
        /// <param name="all"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        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;
        }

        /// 
        /// 数值转换参数
        /// 
        /// <param name="DataUint32"></param>
        /// <returns></returns>
        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;
        }

        /// 
        /// 计算线段交点
        /// 
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <param name="c"></param>
        /// <param name="d"></param>
        /// <param name="intersection"></param>
        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
    }

}
  • 写回答

6条回答 默认 最新

  • azure_xiao_hao 2023-03-07 09:42
    关注

    你可以百度

        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;
        }
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(5条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 3月9日
  • 已采纳回答 3月7日
  • 创建了问题 3月2日

悬赏问题

  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持