我有一个从Web服务检索图像的应用程序.Web服务会在发送到C#客户端之前将一些元数据嵌入到映像中.
这是该方法的一部分.它从Response对象检索Stream,并从流中创建一个Image.请注意,我正在使用System.Drawing.Image
,而不是System.Windows.Controls.Image
- 这意味着我不能使用任何ImageSource或BitmapSource.
System.Drawing.Image img = null;
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
Stream stream = response.GetResponseStream();
img = System.Drawing.Image.FromStream(stream);
.......
}
return img;
Run Code Online (Sandbox Code Playgroud)
图像看起来非常精细,但内部嵌入了元数据.图像是PNG格式,还有另一种方法可以从中提取信息Image
.嵌入了总共六个元数据.这里描述了 PNG格式(PNG块).数据保存在"tEXt"块下.
public static Hashtable GetData(Image image)
{
Hashtable metadata = null;
data = new Hashtable();
byte[] imageBytes;
using (MemoryStream stream = new MemoryStream())
{
image.Save(stream, image.RawFormat);
imageBytes = new byte[stream.Length];
imageBytes = stream.ToArray();
}
if (imageBytes.Length <= 8)
{
return null;
}
// Skipping …
Run Code Online (Sandbox Code Playgroud) 我正在遵循此MSDN指南来处理Task中的异常。
这是我写的:
var myTask = Task.Run(() =>
{
throw new Exception("test");
});
try
{
myTask.Wait();
}
catch (Exception e)
{
return false;
}
Run Code Online (Sandbox Code Playgroud)
我已经在catch
块中设置了一个断点,但是在调试运行时,代码没有到达断点,这给了我:
用户代码未处理异常
我不知道发生了什么,因为我非常仔细地遵循了MSDN指南中的示例。实际上,我将示例复制到了我的项目中,但仍然存在相同的问题。
我可以在任务外处理异常的任何方法吗?如果任务是否抛出任何异常,我需要根据事实返回一个布尔值。
为了让您更清楚一些,这是一组更完整的代码:
public bool ConnectToService()
{
try
{
// Codes for ServiceHost etc etc, which I'm skipping
// These codes are already commented out for this test, so they do nothing
var myTask = Task.Run(() =>
{
// Supposed to connect to a WCF service, but just throwing a …
Run Code Online (Sandbox Code Playgroud) 当我绑定这两个属性时会发生什么?
ObjectProperty<Object> propertyA = new SimpleObjectProperty<>();
ObjectProperty<Object> propertyB = new SimpleObjectProperty<>();
propertyA.set(new ObjectA());
propertyB.set(new ObjectB());
Bindings.bindBidirectional(propertyA, propertyB);
Run Code Online (Sandbox Code Playgroud)
如果两个属性都应该持有相同的对象引用,则在此绑定之后,两个属性都将持有ObjectA
或ObjectB
吗?
我有一个GridPane
5 列。这些分别是我hgrow
对列约束的设置。
SOMETIMES
ALWAYS
SOMETIMES
(固定尺寸)SOMETIMES
ALWAYS
整体GridPane
基本上是一个两栏形式的布局。我的第 1 和第 4 列(索引 0 和 3)是字段标签,而第 2 和第 5 列是输入字段(TextField
等)。第 3 列只是两个表单列之间的固定宽度填充。
ComboBox
我的表格中有一些- 有些在左栏,有些在右栏。我已将所有的最大宽度设置ComboBox
为MAX_VALUE
.
当表单加载时,布局看起来像我想要的(两个输入字段列的宽度相等)。但是,当我单击任何一个时ComboBox
,它会导致单击的列的ComboBox
宽度增加 - 这会导致另一个输入字段列减少相同的数量。
我可以交替单击ComboBox
左侧和右侧的 ,并且两列的宽度会不断变化。变化会越来越小,最终列将停止调整大小。最终结果是两列的宽度不相等。
对于库中的另一个控件JFXDatePicker
,我遇到了同样的问题JFoenix
。
我的另一个限制是这个表单在 a 内SplitPane
,所以我必须避免设置明确的宽度。
我能做些什么来解决这个问题?
我想我会在这里附上一个样本,考虑到这个问题的观点有多么少。
@Override
public void start(Stage primaryStage) throws Exception {
VBox root = FXMLLoader.load(getClass().getResource("Test.fxml"));
Scene sc = new Scene(root);
primaryStage.setScene(sc);
primaryStage.show(); …
Run Code Online (Sandbox Code Playgroud) public class BaseClass {
/**
* Gets the value.
*/
public final String getValue() {
// returns something.
}
}
public class SubClass extends BaseClass {
/**
* Gets the value.
* <p/>
* The value is meaningless for SubClass.
*/
@Override // Cannot override final method
public final String getValue() {
super.getValue(); // Not overriding implementation, just javadoc
}
}
Run Code Online (Sandbox Code Playgroud)
我不需要更改最终方法的实现,我只是想为它更改Javadoc.
在以下情况下,REST服务应返回的正确HTTP状态代码是什么?
我知道有关此类命名约定的类似讨论.但是,我遇到了复数首字母缩略词的问题.
public List<Disc> findAllDvds(DiscHolder holder) {}
public List<Disc> findAllDvd(DiscHolder holder) {}
Run Code Online (Sandbox Code Playgroud)
假设我已经决定使用CamelCase作为首字母缩略词,那两者中的哪一个通常更容易被接受?
我知道这将引发基于意见的答案,但有时当你有疑问时,你只需要人们提供建议和反馈.
另外,这里令人困惑的部分findAllDvds
可能意味着一个新的缩写词DVDS
,它可能被认为是令人困惑的.
当我看到这个(第 790-811 行)时,我正在阅读源代码:ConcurrentQueue
//We need do Interlocked.Increment and value/state update in a finally block to ensure that they run
//without interuption. This is to prevent anything from happening between them, and another dequeue
//thread maybe spinning forever to wait for m_state[] to be true;
try
{ }
finally
{
newhigh = Interlocked.Increment(ref m_high);
if (newhigh <= SEGMENT_SIZE - 1)
{
m_array[newhigh] = value;
m_state[newhigh].m_value = true;
}
//if this thread takes up the last slot in the segment, …
Run Code Online (Sandbox Code Playgroud) 有ListChangeListener.Change.wasUpdated()
用于检测ObservableList
通过创建的s 的元素内的变化ObservableList.observableArrayList(Callback<E,Observable[]> extractor)
。
如何检索导致触发更改的确切项目?
可能这个问题还不够清楚,我举个例子。
class Foo {
private StringProperty name = new SimpleStringProperty();
public final StringProperty nameProperty() { return name; }
public final String getName() { return name.get(); }
public final void setName(String n) { name.set(n); }
public Foo(String fooName) { setName(fooName); }
}
// Creates an ObservableList with an extractor
ObservableList<Foo> fooList = FXCollections.observableArrayList(foo -> new Observable[] { foo.nameProperty() });
Foo fooA = new Foo("Hello");
Foo fooB = new Foo("Kitty");
fooList.add(fooA); …
Run Code Online (Sandbox Code Playgroud) API 如此设计有什么原因吗?据我所知,“尝试”和“非尝试”方法之间的区别只是获得或InvalidOperationException
不获得 - 我不明白它与线程安全有什么关系。Queue
这里有一个小问题 - 为什么和不ConcurrentQueue
实现像 那样的通用接口,它将提供统一的方法,无论是否IQueue
使用?Try...