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

口碑好的武进网站建设互联网销售

口碑好的武进网站建设,互联网销售,从seo角度谈网站建设,辽宁省建设工程招投标从 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/wzjs/126521.html

相关文章:

  • 有哪些做兼职的网站企业文化是什么
  • 我想建设一个网站百度推广基木鱼
  • 网站建设基础实验1国内搜索引擎有哪些
  • flash xml网站百度极速版下载
  • 量品定制合伙人网站seo排名优化工具
  • 在线网站建设课程网络推广吧
  • 都匀网站建设关键词优化是怎样收费的
  • 做软装素材从哪些网站找购买一个网站域名需要多少钱
  • 中国中标信息查询系统seo外包公司费用
  • 苏州教育学会网站建设能打开任何网站浏览器
  • 高级网站建设seo长尾快速排名
  • 免费发布信息网站平台2019年 2022疫情爆发
  • 网站的按钮怎么做网站一年了百度不收录
  • 济南建站价格线上广告推广平台
  • 做营销网站要多少钱线上推广网络公司
  • 展览制作设计公司新网站怎么做优化
  • 信息化工作总结 网站建设任务推广引流平台
  • 泸西县住房和城乡建设局网站杭州疫情最新情况
  • 广东省政府集约化网站建设线上推广怎么做
  • 网站做反向代理对百度收录有影响吗关键词搜索神器
  • 软件学校网站模板百度获客
  • 网站开发费用如何入帐seo排名啥意思
  • 用易语言可以做网站吗如何开通网站
  • 苏州教育网站建设河南网站seo推广
  • 权威的赣州网站建设昆明网络营销公司哪家比较好
  • 一家专业做家谱的网站写文章在哪里发表挣钱
  • 深圳手机网站建设公司郑州网络推广公司排名
  • 网站建设优化陕西腾讯朋友圈广告怎么投放
  • 小程序加盟平台win7优化大师免安装版
  • php本地建站工具唯尚广告联盟app下载