当前位置: 首页 > news >正文

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 });
        }
    }
}

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

相关文章:

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

使用用 C# 编写的 asp.net core web 应用程序示例在 Windows 和 Linux web 服务器上处理图像&#xff0c;包括创建散点图和直方图&#xff0c;以及根据需要旋转图像以便正确显示。 这个小型实用程序库需要将 NuGet SixLabors.ImageSharp包&#xff08;版本 3.1.x&#xff09;添…...

湖仓分析|浙江霖梓基于 Doris + Paimon 打造实时/离线一体化湖仓架构

导读&#xff1a;浙江霖梓早期使用 CDH 产品套件搭建了大数据系统&#xff0c;面临业务逻辑冗余、查询效率低下等问题&#xff0c;基于 Apache Doris 进行整体架构与表结构的重构&#xff0c;并基于湖仓一体和查询加速展开深度探索与实践&#xff0c;打造了 Doris Paimon 的实…...

【AI-34】机器学习常用七大算法

以下是对这七大常用算法的浅显易懂解释&#xff1a; 1. k 邻近算法&#xff08;k - Nearest Neighbors&#xff0c;KNN&#xff09; 想象你在一个满是水果的大广场上&#xff0c;现在有个不认识的水果&#xff0c;想知道它是什么。k 邻近算法就是去看离这个水果最近的 k 个已…...

2025年金三银四经典自动化测试面试题

概述 觉得自动化测试很难&#xff1f; 是的&#xff0c;它确实不简单。但是学会它&#xff0c;工资高啊&#xff01; 担心面试的时候被问到自动化测试&#xff1f; 嗯&#xff0c;你担心的没错&#xff01;确实会被经常问到&#xff01; 现在应聘软件测试工程师的岗位&…...

遵循规则:利用大语言模型进行视频异常检测的推理

文章目录 速览摘要01 引言02 相关工作视频异常检测大语言模型 03 归纳3.1 视觉感知3.2 规则生成Normal and Anomaly &#xff08;正常与异常&#xff09;Abstract and Concrete &#xff08;抽象与具体&#xff09;Human and Environment &#xff08;人类与环境&#xff09; 3…...

RFM模型-数据清洗

在进行数据清洗时&#xff0c;主要的目标是确保数据质量良好&#xff0c;以便后续的分析和建模工作能够顺利进行。针对你使用粒子群优化算法改进RFM模型来对电商数据进行用户群像划分的实验&#xff0c;数据清洗环节尤其重要&#xff0c;因为不干净的数据会影响模型的精度和效果…...

文件系统惹(细)

目录 块概念 分区 inode ext2文件系统 Boot Sector Super Block GDP&#xff08;group descriptor table&#xff09; Block Bitmap&#xff08;块位图&#xff09; Inode Bitmap &#xff08;inode位图&#xff09; Data Block inode和Datablock映射 目录和文件名 …...

中望CAD c#二次开发 ——VS环境配置

新建类库项目&#xff1a;下一步 下一步 下一步&#xff1a; 或直接&#xff1a; 改为&#xff1a; <Project Sdk"Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>NET48</TargetFramework> <LangVersion>pr…...

Centos7安装Clickhouse单节点部署

​ 部署流程 1、关闭防火墙&沙盒 关闭防火墙并关闭开机自启动 systemctl stop firewalld && systemctl disable firewalld查看selinux状态是否为disabled&#xff0c;否则修改 [rootlocalhost ~]# getenforce Enforcing修改为disabled vim /etc/selinux/config…...

4.SpringSecurity在分布式环境下的使用

参考 来源于黑马程序员&#xff1a; 手把手教你精通新版SpringSecurity 分布式认证概念说明 分布式认证&#xff0c;即我们常说的单点登录&#xff0c;简称SSO&#xff0c;指的是在多应用系统的项目中&#xff0c;用户只需要登录一次&#xff0c;就可以访 问所有互相信任的应…...

使用 Notepad++ 编辑显示 MarkDown

Notepad 是一款免费的开源文本编辑器&#xff0c;专为 Windows 用户设计。它是替代记事本&#xff08;Notepad&#xff09;的最佳选择之一&#xff0c;因为它功能强大且轻量级。Notepad 支持多种编程语言和文件格式&#xff0c;并可以通过插件扩展其功能。 Notepad 是一款功能…...

Spring 框架数据库操作常见问题深度剖析与解决方案

Spring 框架数据库操作常见问题深度剖析与解决方案 在 Java 开发的广阔天地中&#xff0c;Spring 框架无疑是开发者们的得力助手&#xff0c;尤其在数据库操作方面&#xff0c;它提供了丰富且强大的功能。然而&#xff0c;就像任何技术一样&#xff0c;在实际项目开发过程中&a…...

第一天:爬虫介绍

每天上午9点左右更新一到两篇文章到专栏《Python爬虫训练营》中&#xff0c;对于爬虫有兴趣的伙伴可以订阅专栏一起学习&#xff0c;完全免费。 键盘为桨&#xff0c;代码作帆。这趟为期30天左右的Python爬虫特训即将启航&#xff0c;每日解锁新海域&#xff1a;从Requests库的…...

ECP在Successfactors中paylisp越南语乱码问题

导读 pyalisp:ECP中显示工资单有两种方式&#xff0c;一种是PE51&#xff0c;一种是hrform&#xff0c;PE51就是划线的那种&#xff0c; 海外使用的比较多&#xff0c;国内基本没人使用&#xff0c;hrform就是pdf&#xff0c;可以编辑pdf&#xff0c;这个国内相对使用的人 比…...

Express 中间件分类

一、 按功能用途分类 1. 应用级中间件 这类中间件应用于整个 Express 应用程序&#xff0c;会对每个进入应用的请求进行处理。通过 app.use() 方法挂载&#xff0c;可用于执行一些全局性的任务&#xff0c;像日志记录、请求预处理、设置响应头这类操作。 const express req…...

基于Multi-Runtime的云原生多态微服务:解耦基础设施与业务逻辑的革命性实践

引言&#xff1a;当微服务遭遇复杂性爆炸 在分布式系统复杂度指数级增长的今天&#xff0c;一线开发者平均需要处理27种不同的基础设施组件配置。CNCF最新研究报告指出&#xff0c;采用Multi-Runtime架构可减少83%的非功能性代码编写量&#xff0c;同时使分布式原语&#xff0…...

flutter isolate到底是啥

在 Flutter 中&#xff0c;Isolate 是一种实现多线程编程的机制&#xff0c;下面从概念、工作原理、使用场景、使用示例几个方面详细介绍&#xff1a; 概念 在 Dart 语言&#xff08;Flutter 开发使用的编程语言&#xff09;里&#xff0c;每个 Dart 程序至少运行在一个 Isol…...

Http connect timed out

客户向云端服务请求时&#xff0c;连接云端域名显示连接超时&#xff0c;为什么呢&#xff0c;偶尔会有。 java.net.SocketTimeoutException: connect timed out at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.AbstractPlainSocketI…...

Flutter 异步编程利器:Future 与 Stream 深度解析

目录 一、Future&#xff1a;处理单次异步操作 1. 概念解读 2. 使用场景 3. 基本用法 3.1 创建 Future 3.2 使用 then 消费 Future 3.3 特性 二、Stream&#xff1a;处理连续异步事件流 1. 概念解读 2. 使用场景 3. 基本用法 3.1 创建 Stream 3.2 监听 Stream 3.…...

langchain实现的内部问答系统及本地化替代方案

主旨&#xff1a;问答系统搭建使用langchain要token&#xff0c;本文目的在于一、解析langchain调用过程&#xff0c;二、不使用langchain规避token&#xff0c;而使用本地化部署的方案方向。主要是本地向量化库的建立。 文章目录 主旨&#xff1a;问答系统搭建使用langchain要…...

“新旗手”三星Galaxy S25系列,再次定义了AI手机的进化方向

一年多前&#xff0c;三星Galaxy S24系列正式发布&#xff0c;作为首款由Galaxy AI赋能的AI手机&#xff0c;带来了即圈即搜、通话实时翻译、AI扩图等“神奇能力”。 彼时AI手机还是一个新物种&#xff0c;没有明确的产品定义&#xff0c;体验上也没有“标准答案”。三星Galax…...

JVM的类加载器

什么是类加载器&#xff1f; 类加载器&#xff1a;JVM只会运行二进制文件&#xff0c;类加载器的作用就是将字节码文件加载到JVM中&#xff0c;从而Java 程序能够启动起来。 类加载器有哪些&#xff1f; 启动类加载器(BootStrap ClassLoader):加载JAVA HOME/jre/lib目录下的库…...

Node.js中的模块化:从原理到实践

目录 一、为什么需要模块化&#xff1f; 二、Node.js模块类型解析 2.1 核心模块 2.2 文件模块 2.3 第三方模块 三、CommonJS规范深度解析 3.1 模块加载原理 3.2 模块缓存机制 3.3 循环依赖处理 四、ES Modules新特性 4.1 基本用法 4.2 与CommonJS的差异比较 五、模…...

LLM论文笔记 6: Training Compute-Optimal Large Language Models

Arxiv日期&#xff1a;2022.3.29机构&#xff1a;Google DeepMind 关键词 scaling lawpower law参数量FLOPStokes 核心结论 1. 当前大多数大语言模型&#xff08;如 GPT-3 和 Gopher&#xff09;在计算预算分配上存在问题&#xff0c;模型参数过大而训练数据不足 2. 计算预算…...

数仓:核心概念,数仓系统(ETL,数仓分层,数仓建模),数仓建模方法(星型模型,雪花模型,星座模型)和步骤

数仓建模的核心概念 事实表&#xff08;Fact Table&#xff09;&#xff1a; 存储业务过程的度量值&#xff08;如销售额、订单数量等&#xff09;。 通常包含外键&#xff0c;用于关联维度表。 维度表&#xff08;Dimension Table&#xff09;&#xff1a; 存储描述性信息&…...

markdown|mermaid|typora绘制流程图的连接线类型怎么修改?

1、使用typora绘制流程图。别人例子里面的连线是圆弧&#xff0c;我的画出来就是带折线的 这是卖家秀&#xff1a; 这是买家秀&#xff1a; 无语了有没有&#xff1f; 犹豫了片刻我决定一探究竟&#xff08;死磕&#xff09;。 Typora --> 文件 --> 偏好设置 --》 mar…...

理解WebGPU 中的 GPUDevice :与 GPU 交互的核心接口

在 WebGPU 开发中&#xff0c; GPUDevice 是一个至关重要的对象&#xff0c;它是与 GPU 进行交互的核心接口。通过 GPUDevice &#xff0c;开发者可以创建和管理 GPU 资源&#xff08;如缓冲区、纹理、管线等&#xff09;&#xff0c;并提交命令缓冲区以执行渲染和计算任…...

庞氏骗局(Ponzi Scheme):金融投资与公司经营中的隐形陷阱(中英双语)

庞氏骗局&#xff1a;金融投资与公司经营中的隐形陷阱 庞氏骗局&#xff08;Ponzi Scheme&#xff09;&#xff0c;这个词在金融史上屡见不鲜。从投资骗局到企业经营中的资本运作&#xff0c;庞氏骗局的核心逻辑始终如一&#xff1a;用后来的资金填补前面的缺口&#xff0c;营…...

【黑马点评】 使用RabbitMQ实现消息队列——3.批量获取1k个用户token,使用jmeter压力测试

【黑马点评】 使用RabbitMQ实现消息队列——3.批量获取用户token&#xff0c;使用jmeter压力测试 3.1 需求3.2 实现3.2.1 环境配置3.2.2 修改登录接口UserController和实现类3.2.3 测试类 3.3 使用jmeter进行测试3.4 测试结果3.5 将用户登录逻辑修改回去3.6 批量删除生成的用户…...

前端调用串口通信

项目录结构 node项目 1&#xff09; 安装serialport npm install serialport 2&#xff09;编写index.js 1 const SerialPort require(serialport); 2 var senddata [0x02];//串口索要发送的数据源 3 var port new SerialPort(COM3);//连接串口COM3 4 port.on(open, fun…...

微信小程序请求大模型监听数据块onChunkReceived方法把数据解析成json

自己写的真是案例&#xff0c;onChunkReceived监听到的数据块发现监听到的内容不只是一个块&#xff0c;有时候会是多块&#xff0c;所以自己加了一个循环解析的过程&#xff0c;不知道大家监听到的数据情况是否一致。 在网上翻阅大量资料有的说引入js文件&#xff0c;亲测无效…...

SQL Server STUFF 函数的用法及应用场景

在 SQL Server 中&#xff0c;STUFF 函数是一种强大的字符串处理工具&#xff0c;常用于删除指定位置的字符并插入新的字符。通过这个函数&#xff0c;开发者能够灵活地修改字符串&#xff0c;从而在数据处理、字符串拼接和格式化等方面大显身手。本文将深入探讨 STUFF 函数的语…...

Qt使用CipherSqlite插件访问加密的sqllite数据库

1.下载 git clone https://github.com/devbean/QtCipherSqlitePlugin.git 2.编译CipherSqlite插件 使用qt打开QtCipherSqlitePlugin项目&#xff0c;并构建插件 ​ 3.将构建的插件复制到安装目录 ​ 4.使用DB Browser (SQLCipher)创建数据库并加密 ​ 5.qt使用Ciphe…...

美国哈美顿零件号A203560 HAMILTON 10µl 1701 N CTC (22S/3) A200S 203560

零件号a61092-01 hamilton ml600 电源 110-220 vac 61092-01 零件号a81322 hamilton 1001 tll 1ml 注射器带塞子 81322 零件号a61710-01 hamilton ml600 探头支架 管架 61710-01 零件号a61614-01 hamilton ml600 填充管 12 ga 1219mm 4.57ml 61614-01 零件号a61615-01 ham…...

深入理解 Rust 的迭代器:从基础到高级

1. 迭代器的基础概念 1.1 什么是迭代器&#xff1f; 迭代器是一种设计模式&#xff0c;允许我们逐个访问集合中的元素&#xff0c;而无需暴露集合的内部结构。在 Rust 中&#xff0c;迭代器通过实现 Iterator trait 来定义。该 trait 主要包含一个方法&#xff1a; pub trai…...

聊聊 IP 地址和端口号的区别

在计算机网络中&#xff0c;两个基本概念对于理解设备如何通过网络进行通信至关重要。IP 地址和端口号是 TCP/IP 的典型特征&#xff0c;其定义如下&#xff1a;IP 地址是分配给连接到网络的每台机器的唯一地址&#xff0c;用于定位机器并与其通信。相反&#xff0c;端口号用于…...

地图打包注意事项

地图打包 &#xff08;注意不能大写 后缀也不能&#xff09; 需要文件 objects_n 文件夹 &#xff08;内部大量png文件和plist文件&#xff09;.map.png 小地图tiles_n_n.plist 和tiles_n_n.png 文件sceneAtlasSplitConfigs合并.txt 文件放入 objects_n文件夹 内部(.png文件…...

代码随想录算法营Day38 | 62. 不同路径,63. 不同路径 II,343. 整数拆分,96. 不同的二叉搜索树

62. 不同路径 这题的限制是机器人在m x n的网格的左上角&#xff0c;每次只能向下走一格或者向右走一格。问到右下角有多少条不同路径。这个动态规划的初始状态是第一行和第一列的格子的值都是1&#xff0c;因为机器人只能向右走一格或者向下走一格&#xff0c;所以第一行和第…...

科普:数据仓库中的“指标”和“维度”

在数据仓库中&#xff0c;指标和维度是两个核心概念&#xff0c;它们对于数据分析和业务决策至关重要。以下是对这两个概念的分析及举例说明&#xff1a; 一、指标 定义&#xff1a; 指标是用于衡量业务绩效的关键数据点&#xff0c;通常用于监控、分析和优化企业的运营状况。…...

`Pinia` + `Formily` + `useTable` 实现搜索条件缓存方案

Pinia + Formily + useTable 实现搜索条件缓存方案 背景 在当前的应用体验中,每当用户刷新页面或退出系统时,之前的搜索条件就会消失不见。为了进一步提升工作效率并增强用户体验,希望能够实现这样一个功能:即使用户进行了页面刷新或是暂时离开了平台,再次返回时也能自动…...

Trader Joe‘s EDI 需求分析

Trader Joes成立于1967年&#xff0c;总部位于美国加利福尼亚州&#xff0c;是一家独特的零售商&#xff0c;专注于提供高质量且价格合理的食品。公司经营范围涵盖了各类杂货、冷冻食品、健康食品以及独特的本地特色商品。 EDI需求分析 电子数据交换&#xff08;EDI&#xff…...

【BUG】conda虚拟环境下,pip install安装直接到全局python目录中

问题描述 conda虚拟环境下&#xff0c;有的虚拟环境的python不能使用&#xff08;which python时直接使用全局路径下的python&#xff09;&#xff0c;且pip install也会安装到全局路径中&#xff0c;无法安装到conda虚拟环境中。 解决方案 查看虚拟环境的PIP缓存默认路径&…...

用Shader glsl实现一个简单的PBR光照模型

PBR模型定义了各种光照属性&#xff0c;如基础颜色、金属度、粗糙度等&#xff0c;就像给物体设定各种 “性格特点”。顶点着色器负责把顶点从模型空间转换到裁剪空间&#xff0c;同时计算一些用于光照计算的参数&#xff0c;就像给顶点 “搬家” 并准备好 “行李”。而片段着色…...

Linux系统使用ollama本地安装部署DeepSeekR1 + open-webui

Linux系统使用ollama本地安装部署DeepSeekR1 open-webui 1. 首先&#xff0c;下载安装ollama #下载安装脚本并执行 curl -fsSL https://ollama.com/install.sh | sh #安装完成后查看ollama版本 ollama --version2. 使用ollama下载deepseek #不同的参数规格对硬件有不同的要…...

学习星开源在线考试教育系统

学习星开源考试系统 项目介绍 项目概述&#xff1a; 学习星在线考试系统是一款基于Java和Vue.js构建的前后端分离的在线考试解决方案。它旨在为教育机构、企业和个人提供一个高效、便捷的在线测试平台&#xff0c;支持多种题型&#xff0c;包括但不限于单选题、多选题、判断…...

树莓派通过手机热点,无线连接PC端电脑,进行远程操作

树莓派通过手机热点实现无线连接具有以下几点优势&#xff1a; 1.该方式能够联网&#xff0c;方便在项目开发时下载一些数据包。 2.该方式能够通过手机端查看树莓派IP地址(有些情况树莓派ip地址会发生改变) 借鉴链接如下&#xff1a; 树莓派的使用网线及无线连接方法及手机…...

【工业安全】-CVE-2022-35561- Tenda W6路由器 栈溢出漏洞

文章目录 1.漏洞描述 2.环境搭建 3.漏洞复现 4.漏洞分析 4.1&#xff1a;代码分析 4.2&#xff1a;流量分析 5.poc代码&#xff1a; 1.漏洞描述 漏洞编号&#xff1a;CVE-2022-35561 漏洞名称&#xff1a;Tenda W6 栈溢出漏洞 威胁等级&#xff1a;高危 漏洞详情&#xff1…...

Windows环境管理多个node版本

前言 在实际工作中&#xff0c;如果我们基于Windows系统开发&#xff0c;同时需要维护老项目&#xff0c;又要开发新项目&#xff0c;且不同项目依赖的node版本又不同时&#xff0c;那么就需要根据项目切换不同的版本。本文使用Node Version Manager&#xff08;nvm&#xff0…...

git 沙盒 下(二)

url &#xff1a;Learn Git Branching 高级git 多次Rebase 最开始我先把bugFix分支先rebase到main上&#xff0c;之后再把c7合并到c6 &#xff0c;之后就差合并为一个分支了&#xff0c;但是无论移动c7还是another分支都无法合并&#xff0c;都会在原地停留 后来根据提示最…...

基于JavaSpringmvc+myabtis+html的鲜花商城系统设计和实现

基于JavaSpringmvcmyabtishtml的鲜花商城系统设计和实现 &#x1f345; 作者主页 网顺技术团队 &#x1f345; 欢迎点赞 &#x1f44d; 收藏 ⭐留言 &#x1f4dd; &#x1f345; 文末获取源码联系方式 &#x1f4dd; &#x1f345; 查看下方微信号获取联系方式 承接各种定制系…...