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

上谷网络网站建设深圳网站建设推广优化

上谷网络网站建设,深圳网站建设推广优化,福建建设中心网站,wordpress虎嗅网源码从 MVC 控制器内部创建位图图像并将其发送到浏览器;用 C# 编写并与 Linux 和 Windows 服务器兼容。 使用从 ASP.NET MVC 中的控制器下载任何文件类型File。 此示例创建一个位图 (jpeg) 并将其发送到浏览器。它需要 NuGet 包SixLabors.ImageSharp v1.0.4。 另请参…

        从 MVC 控制器内部创建位图图像并将其发送到浏览器;用 C# 编写并与 Linux 和 Windows 服务器兼容。

使用从 ASP.NET MVC 中的控制器下载任何文件类型File。

此示例创建一个位图 (jpeg) 并将其发送到浏览器。它需要 NuGet 包SixLabors.ImageSharp v1.0.4。

另请参阅:SixLabors.ImageSharp 图像实用程序类

另请参阅:将文件上传到浏览器后删除

下面的代码将创建以下四幅图像并在它们之间交替显示:

修改后的HomeController.cs文件: 

// HomeController.cs
using Microsoft.AspNetCore.Mvc;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;

namespace WebApplication1.Controllers
{
    public class HomeController : Controller
    {
        static private byte mod(int x, int y) // NOTE: only returns values 0 to 255
        {
            if ((y & 1) == 0) // NOTE: then base of 2 - no need for division
                return (byte)(x & (y - 1));
            else
                return (byte)(x % y);
        }
        static private void Image0(Image<Rgb24> bmp) // NOTE: this will create a colorful bitmap with colorful stars
        {
            // NOTE: loop through every pixel of the bitmap
            for (int x = 0; x < bmp.Width; x++)
                for (int y = 0; y < bmp.Height; y++)
                {
                    byte p = (byte)(x * y >> 8), c = mod(p, 3), z = 255; // NOTE: "z" can be any shade between 0 and 255
                    bmp[x, y] = new Rgb24(c == 0 ? p : z, c == 1 ? p : z, c == 2 ? p : z); // NOTE: set the color of the pixel at (x, y)
                }
        }
        static private void Image1(Image<Rgb24> bmp) // NOTE: this will create a bitmap with a pattern that repeats
        {
            // NOTE: loop through every pixel of the bitmap
            for (int x = 0; x < bmp.Width; x++)
                for (int y = 0; y < bmp.Height; y++)
                {
                    byte p = mod(x * y, 256), c = mod(p, 3), z = 0; // NOTE: "z" can be any shade between 0 and 255
                    bmp[x, y] = new Rgb24(c == 0 ? p : z, c == 1 ? p : z, c == 2 ? p : z); // NOTE: set the color of the pixel at (x, y)
                }
        }
        static private void Image2(Image<Rgb24> bmp) // NOTE: this will create a bitmap with a unique diagonal pattern
        {
            // NOTE: loop through every pixel of the bitmap
            for (int x = 0; x < bmp.Width; x++)
                for (int y = 0; y < bmp.Height; y++)
                {
                    byte p = mod(x, y), c = mod(p, 3), z = 127; // NOTE: "z" can be any shade between 0 and 255
                    bmp[x, y] = new Rgb24(c == 0 ? p : z, c == 1 ? p : z, c == 2 ? p : z); // NOTE: set the color of the pixel at (x, y)
                }
        }
        static private void Image3(Image<Rgb24> bmp) // NOTE: this will create a bitmap of noise
        {
            var rand = new Random();
            // NOTE: loop through every pixel of the bitmap
            for (int x = 0; x < bmp.Width; x++)
                for (int y = 0; y < bmp.Height; y++)
                {
                    byte p = mod(rand.Next(), 256), c = mod(p, 3), z = 255; // NOTE: "z" can be any shade between 0 and 255
                    bmp[x, y] = new Rgb24(c == 0 ? p : z, c == 1 ? p : z, c == 2 ? p : z); // NOTE: set the color of the pixel at (x, y)
                }
        }
        public IActionResult Index()
        {
            int image = int.Parse(Request.Cookies["image"] ?? "0");
            Response.Cookies.Append("image", (image + 1).ToString());
            const int shift = 9;
            const int width = 1 << shift, height = 1 << shift;
            using (var bmp = new Image<Rgb24>(width, height)) // NOTE: create 24-bit bitmap
            {
                switch (mod(image, 4))
                {
                    case 0:
                        Image0(bmp);
                        break;
                    case 1:
                        Image1(bmp);
                        break;
                    case 2:
                        Image2(bmp);
                        break;
                    case 3:
                        Image3(bmp);
                        break;
                }
                byte[] data;
                using (var ms = new MemoryStream())
                {
                    bmp.SaveAsJpeg(ms); // NOTE: save the bitmap as a JPEG image to the stream
                    data = ms.ToArray();

                }
                // NOTE: alternatively, send the data to the browser as a download with the file name "attachment.jpg" by uncommenting the following line
                // return File(data, System.Net.Mime.MediaTypeNames.Image.Jpeg, "attachment.jpg");

                return File(data, System.Net.Mime.MediaTypeNames.Image.Jpeg); // NOTE: send the data to the browser as a file of mime type "image/jpeg"
            }
        }
    }
}

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

http://www.dtcms.com/a/413185.html

相关文章:

  • 深圳网站建设中为策划书平台建设部分
  • 网站需要数据库吗安徽做网站电话
  • 哪些网站是用asp.net开发的深圳哪家做网站最好
  • 做个企业网站大概多少费用四川建设部网站
  • 电子商务和网络购物网站网页设计工作流程
  • 如何确定网站栏目wap网站的开发
  • wordpress网站放icp万网网站发布
  • 如何打击网站首页调用网站栏目id
  • 二维码生成器在线宁波seo教程推广平台
  • 网站建设的用途是什么wordpress搜索框
  • 衡水网站建设最新报价新网站建设方案
  • 假网站如何做销售管理系统业务处理流程
  • 亦庄网站设计搜索引擎优化效果
  • 纳米抗体(Nb):从驼科动物独特抗体到生物医学 “万能工具”,小片段如何释放大能量?
  • 优质网站的衡量标准重庆建设工程查询网站
  • 甘肃seo网站win2003 网站服务器
  • 做网站技术服务合同阳江seo优化
  • 洛阳建设银行官方网站最新中高风险地区名单
  • 有哪些游戏可以做网站网站的建设ppt模板
  • 网站肯定被k亿网联播
  • 前端做网站之后的感想总结网站建设方案实训总结
  • 网站cms模板电商网站域名规则
  • 金泉网做网站电话免费查企业最好的网站
  • 网站怎么做域名解析洛可可在线设计平台
  • 南宁专业做网站网站无法排版
  • 做网站用不用云服务器在线图片修改
  • 哪个公司制作企业网站阿里云企业网站备案流程
  • 专门做销售培训的网站短链接在线生成官网免费
  • GLM-4.5V 与 GLM-4.1V-Thinking:迈向通用多模态推理的新里程碑
  • 开封市建设局网站wordpress 区块链媒体