首页 > 其他分享 >Wpf Bitmap(Image)Base64,Url,文件Path,Stream转BitmapSource(ImageSource),无需外部dll

Wpf Bitmap(Image)Base64,Url,文件Path,Stream转BitmapSource(ImageSource),无需外部dll

时间:2023-12-21 15:45:07浏览次数:41  
标签:return BitmapSource Stream Url System static GetSource public

直接上代码

using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using System.Windows.Media.Imaging;
 
namespace CommonUtils
{
    /// <summary>
    /// Windows图片处理
    /// </summary>
    public static class WindowsImage
    {
        #region BitmapSource
        /// <summary>
        /// 获取图片源
        /// </summary>
        public static BitmapSource GetSource(Stream stream)
        {
            //已验证stream不可关闭
            return BitmapFrame.Create(stream);
        }
 
        /// <summary>
        /// 获取图片源
        /// </summary>
        public static BitmapSource GetSource(Image image)
        {
            return GetSource(image.Stream());
        }
 
        /// <summary>
        /// 获取图片源
        /// </summary>
        public static BitmapSource GetSource(byte[] bytes)
        {
            return GetSource(bytes.ToStream());
        }
 
        /// <summary>
        /// 获取图片源
        /// </summary>
        public static BitmapSource GetSourceFromBase64(string base64)
        {
            return GetSource(base64.Base64Decode());
        }
 
        /// <summary>
        /// 获取图片源
        /// </summary>
        public static BitmapSource GetSourceFromUrlOrPath(string urlOrPath)
        {
            return new BitmapImage(new Uri(urlOrPath));
        }
        #endregion
 
        /// <summary>
        /// 获取截屏
        /// </summary>
        public static Bitmap GetScreenShoot()
        {
            Bitmap bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
            Graphics graphics = Graphics.FromImage(bitmap);
            graphics.CopyFromScreen(new Point(0, 0), new Point(0, 0), bitmap.Size);
            graphics.Dispose();
            return bitmap;
        }
    }
}

 

标签:return,BitmapSource,Stream,Url,System,static,GetSource,public
From: https://www.cnblogs.com/webenh/p/17919223.html

相关文章

  • postman 切换不同环境URL
    一、环境变量环境1和环境2VARIABLE一定一致,INITIAL和CURRENT_VALUE一致;二、配置URL把步骤一的VARIABLE拼接到其你去路径前面{{demoUrl}}三、切换环境右上角环境1和环境2进行切换,OK   ......
  • des加密,url编码,url解码,des解密 DEMO
    des加密,url编码,url解码,des解密DEMOpackagecom.example.core.mydemo.des;importjavax.crypto.Cipher;importjavax.crypto.SecretKey;importjavax.crypto.SecretKeyFactory;importjavax.crypto.spec.DESKeySpec;importjava.net.URLDecoder;importjava.net.URLEncod......
  • JS获取 URL 链接参数
    方法一源码:functionGetQueryString(name){varreg=newRegExp("(^|&)"+name+"=([^&]*)(&|$)");varr=window.location.search.substr(1).match(reg);if(r!=null)returnunescape(r[2]);returnnull;}使用:consol......
  • 测试 doris stream load 数据流
    root@tc-doris-fe-1:~#vimdata.csvroot@tc-doris-fe-1:~#curl--location-trusted-uroot-T./data.csv-H"label:label_example"-H"column_separator:,"-H"columns:id,name"http://10.30.81.5:8030/api/ops_test/test_error_log/......
  • 比Wget、Curl更强大的下载工具! 转载
    作者:Escape 链接:https://www.escapelife.site/posts/7a3b6469.htmlaria2是一款轻量且高效的命令行下载工具。堪称下载利器!介绍说明轻量、高效、命令行aria2 是一款轻量且高效命令行下载工具,它提供了对多协议和多源地址的支持,并尝试将下载带宽利用率最大化,目前支持的协......
  • java.io.FileInputStream#read(byte[]) 阻塞导致没办法继续执行的问题处理
    在对设备节点进行操作的时候,发现读的时候进入阻塞状态(可能是设备节点异常),导致没办法继续执行后面的代码 查看了一下,文件的方式读,是没办法配置超时的自动报异常的设计了一段代码,针对读阻塞做异常处理 publicstaticStringsendCmdToFile(StringfromFile,Stringcmd......
  • 无涯教程-URL Processing函数
    URL代表"统一资源定位器",代表万维网上的资源,例如网页或FTP目录。本节向您展示如何编写与URL通信的Java程序。URL可以分为以下部分:protocol://host:port/path?query#ref例sofprotocolsincludeHTTP,HTTPS,FTP,andFile.Thepathisalsoreferredtoasthefilen......
  • 处理application/octet-stream格式的文件下载
     exportfunctiondownloadFile(url,data){axios({method:'post',url:Vue.prototype.myUrl+url,headers:{'x-auth-token': window.localStorage.getItem('token')},responseType:'blob',data:data......
  • HTTP事件流 text/event-stream
    GitHubAll-in-oneOpenAIDemo一、依赖<dependency><groupId>org.asynchttpclient</groupId><artifactId>async-http-client</artifactId><version>2.12.3</version></dependency>二、事件流处理器@Slf4jpublicclass......
  • HTTP事件流 text/event-stream
    GitHubAll-in-oneOpenAIDemo一、依赖<dependency><groupId>org.asynchttpclient</groupId><artifactId>async-http-client</artifactId><version>2.12.3</version></dependency>二、事件流处理器@Slf4jpublicclass......