Resource and Embedded Resource

本文详细解释了C#应用中资源和嵌入式资源的概念及用法,包括如何通过Uris访问WPF资源,以及不同类型的资源文件在核心.NET框架和支持的差异。此外,还介绍了各种构建行动设置及其对项目输出的影响,如无、编译、内容、嵌入资源等。

Here are one explaination on the Embedded Resource and the Resource.  In this page : 

    in "what is the difference between a Resource and an Embedded Resource in C# application"


“Resource” and “Content” build actions are to access the WPF resources using the Uris. However “Embedded Resource” is for prior technologies. However both options embeds the resource in assembly but “Resource” option to be used for WPF.


And the MSDN has more explaination "Embedded And Linked resources"


If you set the build action for a WPF item to be "Resource", you can leverage embeded resource as supported by the core .NET framewor, but adds support for accessing the embedded resource via a pack UI, from MSDN:

WPF resource files are not the same as the embedded or linked type of resources that can be configured using the core .NET Framework support for assembly resources. While WPF resource files do leverage the core .NET Framework embedded resource support, the ability to access WPF resource files using pack URIs is easier than using namespaces.



Also, there is some detailed explaination on different build action and how it affect the build output for the items.

   

What are the various “Build action” settings in VS.NET project properties and what do they do?


  • None: The file is not included in the project output group and is not compiled in the build process. An example is a text file that contains documentation, such as a Readme file.

  • Compile: The file is compiled into the build output. This setting is used for code files.

  • Content: Allows you to retrieve a file (in same dir as assembly) as a stream via Application.GetContentStream( uri ). For this method to work, it needs a AssemblyAssociatedContentFile custom attribute which VS graciously adds when you mark a file as "Custom"

  • Embedded resource: embeds the file in an exclusive assembly manifest resource.

  • Resource (wpf only): embeds the file in a shared (by all files in the assembly with similar setting) assembly manifest resource named AppName.g.resources.

  • Page (wpf only): Used to compile a xaml file into baml. The baml is then embedded with the same technique as Resource (i.e. available as `AppName.g.resources)

  • ApplicationDefinition (wpf only): Mark the XAML/class file that defines your application. You specify the code-behind with the x:Class="Namespace.ClassName" and set the startup form/page with StartupUri="Window1.xaml"

  • SplashScreen (wpf only): An image that is marked as SplashScreen is shown automatically when an WPF application loads, and then fades

  • DesignDataunknown

  • DesignDataWithDesignTimeCreatableTypesunknown

  • EntityDeploy(Entity Framework)used to deploy the Entity Framework artifacts


Embedded Wizard 是一个用于开发嵌入式图形用户界面(GUI)的工具,它支持将图像资源转换为适合嵌入式系统使用的格式。生成的资源代码中包含的图片数据通常经过优化以适应内存限制性能要求。 在 Embedded Wizard 生成的资源代码中,图片数据通常以 C 或 C++ 兼容的数组形式表示。这些数组存储了图像的原始二进制数据,通常是像素值的集合,具体格式取决于图像的颜色深度编码方式。例如: - **单色图像**:每个像素用 1 位表示,0 表示黑色,1 表示白色。 - **灰度图像**:每个像素用 8 位表示,范围从 0(黑)到 255(白)。 - **RGB 图像**: - RGB565:每个像素用 16 位表示,红色占 5 位,绿色占 6 位,蓝色占 5 位。 - RGB888:每个像素用 24 位表示,红、绿、蓝各占 8 位。 - **ARGB 图像**:在 RGB 的基础上增加了一个 Alpha 通道,用于表示透明度。例如 ARGB8888 表示每个分量各占 8 位,总共 32 位[^1]。 以下是 Embedded Wizard 中生成的一个 RGB565 格式的图像数据示例代码: ```c const unsigned short Image_RGB565_Data[] = { 0xF800, 0x07E0, 0x001F, 0xFFFF, // 示例像素数据 0xFFE0, 0x07FF, 0x0000, 0x0000 }; ``` 在上述代码中,`Image_RGB565_Data` 是一个无符号短整型数组,用于存储图像的像素值。每个像素占用两个字节(16 位),符合 RGB565 的格式定义。 此外,Embedded Wizard 支持多种图像压缩技术,如 RLE(Run-Length Encoding)压缩,这可以进一步减少图像数据所占用的内存空间。压缩后的数据会在运行时解压并渲染到屏幕上。 ### 常见的图像数据格式 - **Raw 数据**:未压缩的原始像素数据,直接按照特定颜色格式排列。 - **RLE 压缩数据**:通过 Run-Length Encoding 压缩算法减少冗余数据,适用于具有大面积相同颜色的图像。 - **JPEG/PNG 压缩数据**:对于需要更高效压缩比的情况,Embedded Wizard 可能会支持 JPEG 或 PNG 等标准图像格式的压缩数据,但这类功能通常依赖于外部解码库[^1]。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值