我有这段代码
Task.Run(async () =>
{
stream = await DependencyService.Get<IPicturePicker>().GetImageStreamAsync();
if (stream != null)
{
Device.BeginInvokeOnMainThread(() =>
{
ImageOne.Source = ImageSource.FromStream(() => stream);
ImageTwo.Source = ImageSource.FromStream(() => stream);
});
}
}
代码的问题是只有ImageTwo.Source被设置(因为它是最后一个)。如何使用相同的流设置ImageOne和ImageTwo?有没有比我正在做的更好的方法呢?
答案 0 :(得分:1)
以下是您可以做的事情:
Device.BeginInvokeOnMainThread(async () =>
{
Stream stream = await DependencyService.Get<IPicturePicker>().GetImageStreamAsync();
var memoryStream = new MemoryStream();
await stream.CopyToAsync(memoryStream);
image1.Source = ImageSource.FromStream(() => { return new MemoryStream(memoryStream.ToArray()); });
image2.Source = ImageSource.FromStream(() => { return new MemoryStream(memoryStream.ToArray()); });
});
答案 1 :(得分:0)
也许你可以这样做:
$today = date("Y-m-d");
$todaytime = strtotime($today);
$testdate = "2017-06-31";
$testtime = strtotime($testdate);
$back7days = strtotime("-7 days",$todaytime);
if($testtime < $back7days)
echo "X"; // do somthing if testdate was more than 7 days ago
$fwd7days = strtotime("+7 days", $todaytime);
if($testtime > $fwd7days)
echo "Y"; // do somthing if testdate is more than 7 days in future
你应该测试,我没有尝试过。