wpf 单选按钮控件

Hui Liu-MSFT 40,666 信誉分 Microsoft 供应商
2024-04-03T05:32:55.47+00:00

你好,我有一张****.png的照片。我想把内容变成图片。谁能帮我......谢谢

C# 代码: <RadioButton GroupName=“Group_1” Name=“Option_1” Content=“Test” Visibility=“Visible” Canvas.Left=“336” Canvas.Top=“216” height=“44” width=“181”/>

Note:此问题总结整理于:wpf RadioButton control

Windows Presentation Foundation
Windows Presentation Foundation
.NET Framework 的一部分,它提供统一的编程模型,用于在 Windows 上构建业务线桌面应用程序。
57 个问题
0 个注释 无注释
{count} 票

接受的答案
  1. Jiale Xue - MSFT 34,201 信誉分 Microsoft 供应商
    2024-04-03T06:29:21.9+00:00

    您可以使用 Graphics.DrawString 在图像中添加上下文,我将为您提供我的方法:

     public void AddContext()  
            {  
                string dir = "C:\\Users\......\\Pictures\\Img.png";  
                if (File.Exists(dir))  
                {  
                    FileStream fs = new FileStream(dir, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);  
                    byte[] bytes = new byte[fs.Length];  
                    fs.Read(bytes, 0, bytes.Length);  
                    fs.Close();  
                    MemoryStream ms = new MemoryStream(bytes);  
                    Bitmap img = new Bitmap(ms);  
                    Graphics g = Graphics.FromImage(img);  
                    String str = "This is Content!!";  
                    Font font = new Font("Arial", 20);  
                    SolidBrush sbrush = new SolidBrush(System.Drawing.Color.Red);  
                    g.DrawString(str, font, sbrush, new PointF(20, 30));  
                    img.Save("123.jpg", System.Drawing.Imaging.ImageFormat.Png);  
      
                }  
            }  
    

    reslut 是: 13041-165522.jpg

    如何使用 WrapPanel 将图像和内容包含在 RadioButton 的内容中。

    <RadioButton GroupName="Group_1" Name="Option_1" Visibility="Visible" Canvas.Left="336" Canvas.Top="216" Height="44" Width="181">
            <WrapPanel>
                <Image Source="C:\Pictures\Myico.ico"></Image>
                <TextBlock Text="Content" Foreground="Red"  FontFamily="Comic Sans MS" FontWeight="Bold" VerticalAlignment="Center"></TextBlock>
            </WrapPanel>
        </RadioButton>
    

    如果答案是正确的,请点击“接受答案”并点赞。 如果您对此答案还有其他疑问,请点击“评论”。

    注意:如果您想接收相关电子邮件,请按照我们的文档中的步骤启用电子邮件通知 此线程的通知。

    0 个注释 无注释

0 个其他答案

排序依据: 非常有帮助