ASP.NET Core SixLabors.ImageSharp v3.x 的图像实用程序类

        使用用 C# 编写的 asp.net core web 应用程序示例在 Windows 和 Linux web 服务器上处理图像,包括创建散点图和直方图,以及根据需要旋转图像以便正确显示。
这个小型实用程序库需要将 NuGet SixLabors.ImageSharp包(版本 3.1.x)添加到.NET 6 / .NET 8项目。它与Windows、Linux和 MacOS兼容。

它可以根据百万像素数或长度乘以宽度来调整图像大小,并根据需要保留纵横比。

它根据EXIF数据旋转/翻转图像。这是为了适应移动设备。

它还创建散点图和直方图。

另请参阅:MVC 应用程序的位图图像创建和下载

using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Metadata.Profiles.Exif;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Formats.Png;
using System.IO;
using System;
using SixLabors.ImageSharp.Formats.Jpeg;

namespace ImageUtil
{
    public class GetSize
    {
        public GetSize(Stream stream)
        {
            using (Image iOriginal = Image.Load(stream))
            {
                stream.Position = 0;
                Width = iOriginal.Width;
                Height = iOriginal.Height;
            }
        }

        /// <summary>
        /// The width of the image specified in the class constructor's Stream parameter
        /// </summary>
        public int Width { get; }

        /// <summary>
        /// The height of the image specified in the class constructor's Stream parameter
        /// </summary>
        public int Height { get; }
    }

    public static class Resize
    {
        /// <summary>
        /// Resize and save an image to a Stream specifying its new width and height
        /// </summary>
        public static void SaveImage(Stream imageStream, int newWidth, int newHeight, bool preserveImageRatio, Stream saveToStream, int jpegQuality = 100)
        {
            using (Image iOriginal = Image.Load(imageStream))
            {
                imageStream.Position = 0;
                if (preserveImageRatio)
                {
                    float percentWidth = newWidth / (float)iOriginal.Width;
                    float percentHeight = newHeight / (float)iOriginal.Height;
                    float percent = percentHeight < percentWidth ? percentHeight : percentWidth;
                    newWidth = (int)Math.Round(iOriginal.Width * percent, 0);
                    newHeight = (int)Math.Round(iOriginal.Height * percent, 0);
                }
                resize(imageStream, iOriginal, newWidth, newHeight, saveToStream, jpegQuality);
            }
        }

        /// <summary>
        /// Resize and save an image to a Stream specifying the number of pixels to resize to
        /// </summary>
        public static void SaveImage(Stream imageStream, int newNumberOfPixels, Stream saveToStream, int jpegQuality = 100)
        {
            using (Image iOriginal = Image.Load(imageStream))
            {
                imageStream.Position = 0;
                double ratio = Math.Sqrt(newNumberOfPixels / (double)(iOriginal.Width * iOriginal.Height));
                resize(imageStream, iOriginal, (int)Math.Round(iOriginal.Width * ratio, 0), (int)Math.Round(iOriginal.Height * ratio, 0), saveToStream, jpegQuality);
            }
        }

        private static void resize(Stream origSource, Image image, int newWidth, int newHeight, Stream saveTo, int jpegQuality)
        {
            image.Mutate(x => x.Resize(newWidth, newHeight));
            transformImage(image); // NOTE: transform image AFTER resizing it!!!
            var format = Image.DetectFormat(origSource);
            if (format.Name.ToLower() == "jpeg")
            {
                var encoder = new JpegEncoder() { Quality = jpegQuality };
                image.SaveAsJpeg(saveTo, encoder);
            }
            else
                image.Save(saveTo, format);
        }
        private static void transformImage(Image image)
        {
            IExifValue? exifOrientation = null;
            var values = image.Metadata?.ExifProfile?.Values;
            if (values != null)
                foreach (var value in values)
                    if (value != null)
                        if (value.Tag == ExifTag.Orientation)
                            exifOrientation = value;

            if (exifOrientation == null)
                return;

            RotateMode rotateMode;
            FlipMode flipMode;
            setRotateFlipMode(exifOrientation, out rotateMode, out flipMode);

            image.Mutate(x => x.RotateFlip(rotateMode, flipMode));
            image.Metadata.ExifProfile.SetValue(ExifTag.Orientation, (ushort)1);
        }
        private static void setRotateFlipMode(IExifValue exifOrientation, out RotateMode rotateMode, out FlipMode flipMode)
        {
            var orientation = (ushort)exifOrientation.GetValue();

            switch (orientation)
            {
                case 2:
                    rotateMode = RotateMode.None;
                    flipMode = FlipMode.Horizontal;
                    break;
                case 3:
                    rotateMode = RotateMode.Rotate180;
                    flipMode = FlipMode.None;
                    break;
                case 4:
                    rotateMode = RotateMode.Rotate180;
                    flipMode = FlipMode.Horizontal;
                    break;
                case 5:
                    rotateMode = RotateMode.Rotate90;
                    flipMode = FlipMode.Horizontal;
                    break;
                case 6:
                    rotateMode = RotateMode.Rotate90;
                    flipMode = FlipMode.None;
                    break;
                case 7:
                    rotateMode = RotateMode.Rotate90;
                    flipMode = FlipMode.Vertical;
                    break;
                case 8:
                    rotateMode = RotateMode.Rotate270;
                    flipMode = FlipMode.None;
                    break;
                default:
                    rotateMode = RotateMode.None;
                    flipMode = FlipMode.None;
                    break;
            }
        }
    }

    /* CREATE A SCATTER PLOT JPEG/PNG IMAGE */
    public static class ScatterPlot
    {
        static readonly Rgba32 WHITE = new Rgba32(255, 255, 255);
        static readonly Rgba32 BLACK = new Rgba32(0, 0, 0);
        static readonly Rgba32 RED = new Rgba32(255, 0, 0);
        static readonly Rgba32 BLUE = new Rgba32(0, 0, 255);
        static readonly Rgba32 GREEN = new Rgba32(0, 192, 0);
        static readonly Rgba32 PURPLE = new Rgba32(128, 0, 128);
        static readonly Rgba32 ORANGE = new Rgba32(255, 164, 0);
        static readonly Rgba32 YELLOW = new Rgba32(255, 225, 0);
        static readonly Rgba32 MAGENTA = new Rgba32(255, 0, 255);
        static readonly Rgba32 AQUA = new Rgba32(0, 225, 255);
        static readonly Rgba32 BLUEJEAN = new Rgba32(0, 128, 255);
        static readonly Rgba32 BROWN = new Rgba32(150, 75, 50);
        static readonly Rgba32 CHARTREUSE = new Rgba32(223, 255, 0);
        static readonly Rgba32 DODGERBLUE = new Rgba32(30, 144, 255);
        static readonly Rgba32 NAVY = new Rgba32(0, 0, 128);
        static readonly Rgba32 DARKRED = new Rgba32(139, 0, 0);
        static readonly Rgba32[] colors = new Rgba32[] { WHITE, BLACK, RED, BLUE, GREEN, PURPLE, ORANGE, YELLOW, MAGENTA, AQUA, BLUEJEAN, BROWN, DODGERBLUE, CHARTREUSE, NAVY, DARKRED };
        public static void CreateJPEG(Stream stream, ScatterPlotColors backgroundColor, IEnumerable<PlotPoint> points, int width, int height, int pointSize, int jpegQuality = 100)
        {
            using (var bmp = new Image<Rgba32>(width / pointSize + 6, height / pointSize + 6, colors[(int)backgroundColor]))
                create(stream, width, height, bmp, points, pointSize, new JpegEncoder() { Quality = jpegQuality });
        }
        public static void CreateJPEG(string filename, ScatterPlotColors backgroundColor, IEnumerable<PlotPoint> points, int width, int height, int pointSize, int jpegQuality = 100)
        {
            using (var stream = File.Create(filename))
                CreateJPEG(stream, backgroundColor, points, width, height, pointSize, jpegQuality);
        }

        public static void CreatePNG(Stream stream, IEnumerable<PlotPoint> points, int width, int height, int pointSize)
        {
            using (var bmp = new Image<Rgba32>(width / pointSize + 6, height / pointSize + 6))
                create(stream, width, height, bmp, points, pointSize, new PngEncoder());
        }
        public static void CreatePNG(string filename, IEnumerable<PlotPoint> points, int width, int height, int pointSize)
        {
            using (var stream = File.Create(filename))
                CreatePNG(stream, points, width, height, pointSize);
        }

        private static double normalize(float min, float max, float value)
        {
            double x = max - min;
            if (x == 0)
                return 0;
            return (value - min) / x;
        }

        private static void create(Stream stream, int width, int height, Image<Rgba32> bmp, IEnumerable<PlotPoint> points, int pointSize, SixLabors.ImageSharp.Formats.IImageEncoder imageEncoder)
        {
            float xMax = float.MinValue, xMin = float.MaxValue, yMax = float.MinValue, yMin = float.MaxValue;
            foreach (var pt in points)
            {
                xMax = Math.Max(pt.x, xMax);
                xMin = Math.Min(pt.x, xMin);
                yMax = Math.Max(pt.y, yMax);
                yMin = Math.Min(pt.y, yMin);
            }
            float xDelta = Math.Max(1, xMax - xMin), yDelta = Math.Max(1, yMax - yMin);
            int w = width / pointSize;
            int h = height / pointSize;
            foreach (var pt in points)
            {
                int x = (int)(w * normalize(xMin, xMax, pt.x));
                int y = (int)(h * normalize(yMin, yMax, pt.y));
                bmp[x + 3, y + 3] = colors[((int)pt.color) % colors.Length];
            }
            bmp.Mutate(x => x.Flip(FlipMode.Vertical));
            bmp.Mutate(x => x.Resize(width, height));
            bmp.Save(stream, imageEncoder);
        }
    }
    public class PlotPoint
    {
        public ScatterPlotColors color { get; }
        public float x { get; }
        public float y { get; }
        public PlotPoint(float x, float y, ScatterPlotColors color)
        {
            this.x = x;
            this.y = y;
            this.color = color;
        }
    }
    public enum ScatterPlotColors
    {
        WHITE,
        BLACK,
        RED,
        BLUE,
        GREEN,
        PURPLE,
        ORANGE,
        YELLOW,
        MAGENTA,
        AQUA,
        BLUEJEAN,
        BROWN,
        CHARTREUSE,
        DODGERBLUE,
        NAVY,
        DARKRED
    }

    /* CREATE A PNG HISTOGRAM OF AN IMAGE */
    public static class Histogram
    {
        /// <summary>
        /// Create a histogram from the data in a stream
        /// </summary>
        public static MemoryStream CreatePNG(Stream stream, int width, int height, LRGB lrgb, byte alphaChannel = 128, bool clipBlackAndWhite = true, byte luminanceShade = 255)
        {
            using (var bmp = Image<Rgb24>.Load(stream))
            {
                return create(bmp, width, height, lrgb, alphaChannel, clipBlackAndWhite, luminanceShade);
            }
        }

        /// <summary>
        /// Create a histogram from the data in a file
        /// </summary>
        public static MemoryStream CreatePNG(string filename, int width, int height, LRGB lrgb, byte alphaChannel = 128, bool clipBlackAndWhite = true, byte luminanceShade = 255)
        {
            using (var bmp = Image<Rgb24>.Load(filename))
            {
                return create(bmp, width, height, lrgb, alphaChannel, clipBlackAndWhite, luminanceShade);
            }
        }

        private static MemoryStream create(Image bmp, int width, int height, LRGB lrgb, byte alpha, bool clip, byte shade)
        {
            ulong[] lumin = new ulong[256];
            ulong[] red = new ulong[256];
            ulong[] green = new ulong[256];
            ulong[] blue = new ulong[256];
            var bred = (lrgb & LRGB.RED) != 0;
            var bgreen = (lrgb & LRGB.GREEN) != 0;
            var bblue = (lrgb & LRGB.BLUE) != 0;
            var blumin = (lrgb == LRGB.LUMINANCE);
            int w = bmp.Width;
            int h = bmp.Height;
            var bmp2 = bmp.CloneAs<Rgb24>();
            for (int y = 0; y < h; y++)
            {
                bmp2.ProcessPixelRows(accessor =>
                {
                    for (int x = 0; x < w; x++)
                    {
                        Span<Rgb24> pixelRow = accessor.GetRowSpan(y);
                        var c = pixelRow[x];
                        lumin[(int)Math.Round((c.R + c.G + c.B) / 3.0)]++;
                        red[c.R]++;
                        green[c.G]++;
                        blue[c.B]++;
                    }
                });
            }
            ulong max = 0;
            int a = (clip ? 1 : 0), b = (clip ? 255 : 256);
            for (int i = a; i < b; i++)
            {
                if (!blumin)
                {
                    if (bred)
                        if (max < red[i])
                            max = red[i];
                    if (bgreen)
                        if (max < green[i])
                            max = green[i];
                    if (bblue)
                        if (max < blue[i])
                            max = blue[i];
                }
                else if (max < lumin[i])
                    max = lumin[i];
            }
            double HEIGHTFACTOR = 256.0 / max;
            if (blumin)
            {
                using (var bmplum = new Image<Rgba32>(256, 256))
                {
                    var penlum = new VerticalPen(new Rgba32(shade, shade, shade, alpha));
                    for (int i = 0; i < 256; i++)
                        penlum.Draw(bmplum, i, (int)(lumin[i] * HEIGHTFACTOR));
                    bmplum.Mutate(x => x.Resize(width, height));
                    MemoryStream ms = new MemoryStream();
                    bmplum.Save(ms, new PngEncoder());
                    return ms;
                }
            }
            else
            {
                using (var bmppre = new Image<Rgba32>(256, 256))
                {
                    Image<Rgba32>? bmpred = null, bmpgreen = null, bmpblue = null;
                    VerticalPen? penred = null, pengreen = null, penblue = null;
                    if (bred)
                    {
                        bmpred = new Image<Rgba32>(256, 256);
                        penred = new VerticalPen(new Rgba32(255, 0, 0, alpha));
                    }
                    if (bgreen)
                    {
                        bmpgreen = new Image<Rgba32>(256, 256);
                        pengreen = new VerticalPen(new Rgba32(0, 255, 0, alpha));
                    }
                    if (bblue)
                    {
                        bmpblue = new Image<Rgba32>(256, 256);
                        penblue = new VerticalPen(new Rgba32(0, 0, 255, alpha));
                    }

                    for (int i = 0; i < 256; i++)
                    {
                        if (bred)
                            penred.Draw(bmpred, i, (int)(red[i] * HEIGHTFACTOR));
                        if (bgreen)
                            pengreen.Draw(bmpgreen, i, (int)(green[i] * HEIGHTFACTOR));
                        if (bblue)
                            penblue.Draw(bmpblue, i, (int)(blue[i] * HEIGHTFACTOR));
                    }

                    if (bred)
                    {
                        bmppre.Mutate(x => x.DrawImage(bmpred, 1));
                        bmpred.Dispose();
                    }
                    if (bgreen)
                    {
                        bmppre.Mutate(x => x.DrawImage(bmpgreen, 1));
                        bmpgreen.Dispose();
                    }
                    if (bblue)
                    {
                        bmppre.Mutate(x => x.DrawImage(bmpblue, 1));
                        bmpblue.Dispose();
                    }
                    bmppre.Mutate(x => x.Resize(width, height));
                    MemoryStream ms = new MemoryStream();
                    bmppre.Save(ms, new PngEncoder());
                    return ms;
                }
            }
        }
        internal class VerticalPen
        {
            private readonly Rgba32 color;
            public VerticalPen(Rgba32 color)
            {
                this.color = color;
            }
            public void Draw(Image<Rgba32> bmp, int row, int height)
            {
                if (height <= bmp.Height)
                    for (int y = height - 1; y >= 0; y--)
                        bmp[row, bmp.Height - 1 - y] = color;
            }
        }
        public enum LRGB
        {
            LUMINANCE = 0,
            RED = 1,
            GREEN = 2,
            BLUE = 4,
            REDBLUE = 1 | 4,
            REDGREEN = 1 | 2,
            BLUEGREEN = 2 | 4,
            REDGREENBLUE = 1 | 2 | 4
        }
    }
}

示例用法
另请参阅:控制台应用程序示例

这是MVC Web 应用程序中的视图。

@{
    ViewData["Title"] = "/Home/UploadImages";
}

<div class="text-center">
    <h1 class="display-4">UploadImages</h1>
    <form enctype="multipart/form-data" method="post">
        <div>
            <input type="file" name="images" accept="image/jpeg, image/gif, image/png" multiple />
        </div>
        <div>
            <button type="submit" class="btn btn-primary">UPLOAD</button>
        </div>
    </form>
    @if(Model is int)
    {
        <p>@Model images saved.</p>
    }
</div>

现在介绍控制器代码。

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.TagHelpers;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using WebApplication1.Models;

namespace WebApplication1.Controllers
{
    public class HomeController : Controller
    {
        private readonly ILogger<HomeController> _logger;

        public HomeController(ILogger<HomeController> logger)
        {
            _logger = logger;
        }

        public IActionResult UploadImages()
        {
            return View();
        }

        [HttpPost]
        [DisableRequestSizeLimit] // NOTE: NOT RECOMMENDED - SET A LIMIT
        public IActionResult UploadImages(IFormCollection form)
        {
            int count = 0;
            foreach(var image in form.Files)
            {
                if(image.ContentType.StartsWith("image/"))
                {
                    using (var openfs = image.OpenReadStream())
                    {
                        string filename = "thumbnail-" + image.FileName;
                        if (System.IO.File.Exists(filename))
                            System.IO.File.Delete(filename);
                        using (var savefs = System.IO.File.OpenWrite(filename))
                        {
                            // NOTE: RESIZE IMAGE TO 10K PIXEL THUMBNAIL; THIS WILL ALSO FLIP AND ROTATE IMAGE AS NEEDED
                            ImageUtil.Resize.SaveImage(openfs, 10000, savefs);
                            count++;
                        }
                    }
                }    
            }
            return View(count);
        }

        public IActionResult Index()
        {
            return View();
        }

        public IActionResult Privacy()
        {
            return View();
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}

如果您喜欢此文章,请收藏、点赞、评论,谢谢,祝您快乐每一天。 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/19563.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【leetcode】200.岛屿数量(DFS入门)

实战总结 用char型接收整形int转化为的对应字符要小心 int res; char res 0; 其中 res 的上限是127。 在下面这道题中&#xff0c;笔者一开始想将遍历过的位置更新值为 res ‘0’&#xff0c;但当岛屿数过多的时候就溢出了&#xff0c;所以还是应该将遍历过的位置更新为‘…

CES Asia 2025“科技+文旅”融合计划:开启文旅新篇

CES Asia 2025第七届亚洲消费电子技术贸易展&#xff08;赛逸展&#xff09;将在首都北京盛大举行&#xff0c;其亮点十三“‘科技文旅’融合计划”备受瞩目&#xff0c;为科技与文旅产业的深度融合带来了新的契机与活力。 在“科技文旅”融合计划中&#xff0c;景区智能设备租…

【Git版本控制器】第三弹——版本回退,撤销修改,删除文件

&#x1f381;个人主页&#xff1a;我们的五年 &#x1f50d;系列专栏&#xff1a;Linux网络编程 &#x1f337;追光的人&#xff0c;终会万丈光芒 &#x1f389;欢迎大家点赞&#x1f44d;评论&#x1f4dd;收藏⭐文章 ​ 相关笔记&#xff1a; https://blog.csdn.net/djd…

DeepSeek ,银行营销会被 AIGC 颠覆吗?

AI 让银行营销更智能&#xff0c;但更重要的是“懂客户” AI 在银行营销中的应用已经不仅仅局限于文案生成&#xff0c;而是渗透到了整个营销流程。 据悉&#xff0c;中国银行已经开始利用 AI 大模型构建智能营销助手系统&#xff0c;结合知识图谱和 AI 技术&#xff0c;实现…

【产品推介】可驱动5A负载的降压型DC/DC转换器XBL1663

一、产品简介 采用ESOP-8封装的XBL1663最大可输出5A电流 芯伯乐XBL1663是一款专为降压型DC/DC转换器设计的单片集成电路&#xff0c;具有高转换效率、恒定开关频率工作的特点。内置功率 MOSFET可在 4.5 V-40V 输入电源上实现 5A 峰值输出电流&#xff0c;并具有出色的负载和线…

Rust编程语言入门教程(四)猜数游戏:一次猜测

目录 引言猜数游戏——目标一、创建项目二、编写代码三、运行代码四、代码解释总结 引言 猜数游戏是一个经典的编程练习&#xff0c;它不仅能够帮助开发者熟悉基本的输入输出操作&#xff0c;还能深入理解条件判断和用户交互的逻辑。在 Rust 中&#xff0c;通过标准库提供的 s…

.NET版PDF处理控件Aspose.PDF教程:在 C# 中将 TIFF 文件转换为 PDF

将TIFF文件转换为PDF文档在各个行业中都是必不可少的。许多企业需要将文档转换为存档、共享或打印。TIFF 文件通常用于图像&#xff0c;而 PDF 是文档共享的标准。将 TIFF 文件转换为 PDF 可确保跨不同平台的兼容性和易用性。在这篇博文中&#xff0c;我们将探讨如何使用 Aspos…

DeepSeek视角下学术论文创新点探索干货分享!

学术论文的创新性是推动知识进步和科学发展的关键因素。它不仅是学术研究的基本要求&#xff0c;也是研究者专业能力的重要体现。本文将探讨学术论文创新的重要性&#xff0c;并分析DeepSeek在促进学术论文创新方面可能发挥的独特作用。 1.创新为啥这么重要&#xff1f; 1. 探…

EasyRTC智能硬件:实时畅联、沉浸互动、消音护航

在当今智能硬件迅猛发展的时代&#xff0c;音视频通讯技术已成为设备与用户、设备与设备间不可或缺的沟通纽带。而EasyRTC&#xff0c;凭借其无可比拟的实时性能、卓越的互动感受以及强大的交互实力&#xff0c;正逐步演变为智能硬件领域的“超级动力”核心。特别是其倾力打造的…

matlab汽车动力学半车垂向振动模型

1、内容简介 matlab141-半车垂向振动模型 可以交流、咨询、答疑 2、内容说明 略 3、仿真分析 略 4、参考论文 略

重生之我在异世界学编程之C语言:深入预处理篇(上)

大家好&#xff0c;这里是小编的博客频道 小编的博客&#xff1a;就爱学编程 很高兴在CSDN这个大家庭与大家相识&#xff0c;希望能在这里与大家共同进步&#xff0c;共同收获更好的自己&#xff01;&#xff01;&#xff01; 本文目录 引言正文一、预处理的作用与流程&#xf…

观察者模式说明(C语言版本)

观察者模式主要是为了实现一种一对多的依赖关系&#xff0c;让多个观察者对象同时监听某一个主题对象。这个主题对象在状态发生变化时&#xff0c;会通知所有观察者对象&#xff0c;使它们能够自动更新自己。下面使用C语言实现了一个具体的应用示例&#xff0c;有需要的可以参考…

Zotero PDF Translate插件配置百度翻译api

Zotero PDF Translate插件可以使用几种翻译api&#xff0c;虽然谷歌最好用&#xff0c;但是由于众所周知的原因&#xff0c;不稳定。而cnki有字数限制&#xff0c;有道有时也不行。其他的翻译需要申请密钥。本文以百度为例&#xff0c;进行申请 官方有申请教程&#xff1a; Zot…

无人机遥感:如何助力智慧农业中的农林信息提取?

目录 综合态势分析农作物形态信息提取理论与实践农作物生理生化信息提取理论与实践农作物胁迫信息提取理论与实践农作物产量信息提取理论与实践遥感提取结果的空间表达——GIS制图流程 前言 无人机遥感技术在农林信息提取中的应用已成为智慧农业和生态监测的重要手段。通过搭载…

【线段树 二分查找】P3939 数颜色|普及+

本文涉及知识点 C线段树 C二分查找 P3939 数颜色 题目背景 大样例可在页面底部「附件」中下载。 题目描述 小 C 的兔子不是雪白的&#xff0c;而是五彩缤纷的。每只兔子都有一种颜色&#xff0c;不同的兔子可能有 相同的颜色。小 C 把她标号从 1 到 n n n 的 n n n 只兔…

网络工程师 (44)ARP协议

前言 ARP协议&#xff0c;即地址解析协议&#xff08;Address Resolution Protocol&#xff09;&#xff0c;是一种网络协议&#xff0c;主要用于将网络层的IPv4地址&#xff08;逻辑地址&#xff09;解析为链路层的物理地址&#xff08;通常是MAC地址&#xff09;。 一、基本概…

深入解析 vLLM:高性能 LLM 服务框架的架构之美(一)原理与解析

修改内容时间2.4.1处理请求的流程&#xff0c;引用更好的流程图2025.02.11首发2025.02.08 深入解析 vLLM&#xff1a;高性能 LLM 服务框架的架构之美&#xff08;一&#xff09;原理与解析 深入解析 vLLM&#xff1a;高性能 LLM 服务框架的架构之美&#xff08;二&#xff09;…

Web安全|渗透测试|网络安全

基础入门(P1-P5) p1概念名词 1.1域名 什么是域名&#xff1f; 域名&#xff1a;是由一串用点分隔的名字组成的Internet上某一台计算机或计算机组的名称&#xff0c;用于在数据传输时对计算机的定位标识&#xff08;有时也指地理位置&#xff09;。 什么是二级域名多级域名&am…

JavaSE的基础语法(5)

一.Java中的方法 函数:把完成某一特定功能的代码进行抽取,把他们卸写在一组大括号中,为其命名通过函数名调用即可 Java中的方法:类似于其他语言中的函数(在面向对象的语言中习惯称之为方法,且不能独立存在,需要定义在类中) 将完成某个特定功能的某一段代码封装到一个有名称的代…

springcloud集成gateway

本篇文章只介绍gateway模块的搭建步骤&#xff0c;并无gateway详细介绍 gateway详解请查看&#xff1a;SpringCloudGateway官方文档详解 前置处理 父模块中已指定版本 不知道如何选择版本看这篇&#xff1a; 手把手教你梳理springcloud与springboot与springcloudalibaba的版本…