当前位置:网站首页>C # practical skills: package the icon into DLL and read it
C # practical skills: package the icon into DLL and read it
2022-06-09 23:42:00 【User 9127601】
summary
Individual project interfaces sometimes need to use a lot of icons , These pictures can be set up in a folder and stored separately , But sometimes it involves the deployment of multiple devices , Each device needs to be copied along with the project , If you forget the interface display, there will be problems , Is there a better way to solve ?
Yes , Of course. , This section introduces a method to solve this problem , Embed pictures into resources DLL Pack together .
Methods to introduce
step1: Click item -》 Right click -》 attribute -》 resources -》 Add resources
step2: Front desk binding
<WrapPanel >
<Image Source="{Binding AddPNG}" Width="15" Height="15" />
<TextBlock Text=" add to " VerticalAlignment="Center" />
</WrapPanel>step3: Background definition and call
public System.Windows.Media.ImageSource AddPNG { get; set; }What is defined here is ImageSource Data of type , The picture needs to be converted : The following methods need to be put into the constructor
AddPNG = ChangeBitmapToImageSource(Caburn.Micro.Hello.Properties.Resources.add); [DllImport("gdi32.dll", SetLastError = true)]
private static extern bool DeleteObject(IntPtr hObject);
/// <summary>
/// from bitmap convert to ImageSource
/// </summary>
/// <param name="icon"></param>
/// <returns></returns>
public static System.Windows.Media.ImageSource ChangeBitmapToImageSource(Bitmap bitmap)
{
//Bitmap bitmap = icon.ToBitmap();
IntPtr hBitmap = bitmap.GetHbitmap();
System.Windows.Media.ImageSource wpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
hBitmap,
IntPtr.Zero,
Int32Rect.Empty,
System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
if (!DeleteObject(hBitmap))
{
throw new System.ComponentModel.Win32Exception();
}
return wpfBitmap;
}then , You run and generate your DLL, No matter where it is used , There is no need to make another copy of this picture . Show results :
In fact, a simpler way is to directly modify the production operation of the picture to Resource, Then in the place of reference :
<Image Source="/Images/userlogin.png"/>If a global style is applied , Need to add Style=“{x:Null}”
边栏推荐
- [volume guide] mendeley document management tool tutorial
- “當你不再是程序員,很多事會脫離掌控”—— 對話全球最大獨立開源公司SUSE CTO
- Two tower model - Semantic Indexing Strategy [in batch negatives]
- Model deployment Brief
- 又一重磅內容|海外現金貸產品形態及風控措施
- 手推单精度浮点类型
- Mazhiqiang: research progress and application of speech recognition technology -- RTC dev Meetup
- Online JSON to CSV tool
- 彭博终端产品覆盖的加密资产数量扩大为前50名资产
- IOS cache - nscache and sandbox cache
猜你喜欢

Swift GCD Notify after concurrent execution Lock barrier

手推单精度浮点类型

qnx系统学习

Manual single precision floating point type

我服了,MySQL表500W行,居然有人不做分区?

iOS 缓存 -- NSCache和沙盒缓存

It only takes eight steps to package the applet to generate an app

Multiplier: how to build a circuit like Lego (Part 2)?

cadence SPB17.4 - allegro - Move With Dynamic Alignment ON/OFF

This configuration section cannot be used in this path. If the section is locked at the parent level, the solution to this situation will occur
随机推荐
What is a distributed software system
鲲鹏DevKit工具基础那些事
只需八步将小程序一键打包生成App
« Lorsque vous n'êtes plus programmeur, beaucoup de choses échappent au contrôle » - conversation avec Suse CTO, la plus grande entreprise open source indépendante au monde
最新活动|OpenHarmony开源开发者成长计划解决方案学生挑战赛即将开启!
记一次应急排查'新'路历程
What is liquidity pledge? What is a farm pledge?
动态读取protobuf数据
2022 practice questions and mock exam of quality controller municipal direction general basic (quality controller) examination
iOS 缓存 -- NSCache和沙盒缓存
Features and functions of IPSec
读书会招募 | 一起来读《蛤蟆先生去看心理医生》吧
C# WPF布局控件LayoutControl介绍
Discussion on solving LCA by multiplication method
C# WPF后台动态添加控件(经典)
在线JSON转CSV工具
Two tower model: Ernie gram pre training and fine-tuning matching
2022年质量员-市政方向-通用基础(质量员)考试练习题及模拟考试
Another important content - Overseas cash loan product form and risk control measures
Experiment 1: configure static routes on FW to realize interworking