[编辑]*我忘了包含退回的异常
'System.Windows.Style' is not a valid value for property 'Fill'*
这是我的第一篇文章,我已经做了很多寻找可能已经得到回答但没有成功的问题.当谈到MVVM,Prism和WPF时,我是一个完整的菜鸟,我已经被深深地抛在了这一点上.
我希望根据Model(Binding Passed)中的布尔值更改2个矩形的内容.
如果测试返回Pass(bool True),则我们为第一个矩形显示绿色,第二个矩形将显示UserControl.Resource Style x:Key ="RectanglePass".如果测试失败,则第一个矩形为红色,第二个显示UserControl.Resource Style x:Key ="RectangleFail"
我有以下xaml代码:
<UserControl x:Class="Integration.Memjet.Aoqc.Views.ProcessResultView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Resources>
<Style x:Key="RectangleFail" TargetType="Rectangle">
<Setter Property="Fill">
<Setter.Value>
<VisualBrush>
....
</VisualBrush>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="RectanglePass" TargetType="Rectangle">
<Setter Property="Fill">
<Setter.Value>
<VisualBrush>
....
</VisualBrush>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="60"></RowDefinition>
<RowDefinition Height="60"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Label VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="20">PASS</Label>
<Rectangle Name="rectStatus" Grid.Row="1">
<Rectangle.Style>
<Style TargetType="{x:Type Rectangle}">
<Style.Triggers>
<DataTrigger …Run Code Online (Sandbox Code Playgroud) 我正在尝试执行以下逻辑:
bitmap_id = 'HelloWorld'
if 'SLIDE' not in bitmap_id and 'ICON' not in bitmap_id and 'BOT' not in bitmap_id:
print bitmap_id
Run Code Online (Sandbox Code Playgroud)
因此,如果bitmap_id为'ICON_helloworld',则不应打印任何内容.
我很确定你们都同意它太长并且看起来很难看,所以我试着按照下面的说明进行操作,但它不起作用.
if any(s not in bitmap_id for s in ['SLIDE', 'ICON', 'BOT']):
print bitmap_id
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
在图像处理方面我非常喜欢:(我有一堆PNG文件(其中300个),我希望裁剪大面积的透明度.我想显然自动化过程,因此为什么我尝试使用python和PIL.
现在我看看以下链接, 将PNG图像裁剪为最小尺寸,并使用此链接建议的Numpy,使用python/PIL自动裁剪图像,两者都没有成功:(输出文件与输入文件!没有裁剪透明度,大小相同.getbbox返回相同的宽度和高度.
这是其中一个图像的链接; 98x50 按钮图像是一个铃铛形状的按钮图标.它是用白色绘制的,因此很难看出哪个透明背景.预期的结果将是一个20x17的按钮(内部透明度为20x17的盒子保持不变)
这是我正在使用的代码;
#!/usr/bin/env python
import sys
import os
import Image
import numpy as np
def autocrop_image2(image):
image.load()
image_data = np.asarray(image)
image_data_bw = image_data.max(axis=2)
non_empty_columns = np.where(image_data_bw.max(axis=0) > 0)[0]
non_empty_rows = np.where(image_data_bw.max(axis=1) > 0)[0]
cropBox = (min(non_empty_rows), max(non_empty_rows),
min(non_empty_columns), max(non_empty_columns))
image_data_new = image_data[cropBox[0]:cropBox[
1] + 1, cropBox[2]:cropBox[3] + 1, :]
new_image = Image.fromarray(image_data_new)
return new_image
def autocrop_image(image, border=0):
# Get the bounding box
bbox = image.getbbox()
# Crop the image to the contents …Run Code Online (Sandbox Code Playgroud)