我正在研究 xamarin.forms。我必须从图库中选择图像,然后调整它们的大小,然后将它们上传到服务器上。但我不知道如何以给定的特定尺寸调整所选图像的大小?请更新我如何做到这一点?
我正在尝试使用MbUnit测试多线程IO类.我的目标是让测试夹具构造函数执行3次,对于类中的每一行执行一次.然后,对于每个实例,在并行线程上多次执行测试.
但是,Icarus在TaskRunner上爆发了"索引超出范围".我无法获得完整的堆栈,它会过快地生成消息框.
我做错了什么,或者这是MbUnit/Gallio中的错误?
using System;
using System.Collections.Generic;
using System.Text;
using Gallio.Framework;
using MbUnit.Framework;
using MbUnit.Framework.ContractVerifiers;
using System.IO;
namespace ImageResizer.Plugins.DiskCache.Tests {
[TestFixture]
[Row(0,50,false)]
[Row(0,50,true)]
[Row(8000,100,true)]
public class CustomDiskCacheTest {
public CustomDiskCacheTest(int subfolders, int totalFiles, bool hashModifiedDate) {
char c = System.IO.Path.DirectorySeparatorChar;
string folder = System.IO.Path.GetTempPath().TrimEnd(c) + c + System.IO.Path.GetRandomFileName();
cache = new CustomDiskCache(folder,subfolders,hashModifiedDate);
this.quantity = totalFiles;
for (int i = 0; i < quantity;i++){
cache.GetCachedFile(i.ToString(),"test",delegate(Stream s){
s.WriteByte(32); //Just one space
},defaultDate, 10);
}
}
int quantity;
CustomDiskCache cache = null;
DateTime …Run Code Online (Sandbox Code Playgroud) 散列#to_s(检查的别名)始终以1.8散列样式输出数据:
{key: "value"}.to_s
=> "{:key=>\"value\"}"
Run Code Online (Sandbox Code Playgroud)
是否有任何核心方法将以1.9散列样式序列化它?
{key: "value"}.to_s
=> "{key: \"value\"}"
Run Code Online (Sandbox Code Playgroud)
我在已知数据上使用它来进行代码重构; 由于Ruby倾向于实现一切,我希望我只是在寻找错误的地方.
当然,你可以用丑陋的方式破解它
"{" + my_hash.to_a.map{|pair| pair[0].to_s + ": " + pair[1].inspect} * ",\n") + "}"
Run Code Online (Sandbox Code Playgroud)
但我希望有一个核心方法可以进行单元测试并完全正确.
该冥王星库为Lua中声称能够序列化的Lua协程.我将其解释为'serializeable continuations',这是使异步编程以同步方式可写的重要特性.
例如,工作流可以线性表示,而不是需要命名的入口点
if (ask user is hungry) then
if (not ask user is vegetarian) then
if (ask user if likes_burgers) then
feed_user(burger)
else
tell_user("Picky!")
else
feed_user(salad)
Run Code Online (Sandbox Code Playgroud)
代替
function main()
ask(user is hungry, "hungry_response")
function hungry_response(answer)
if (answer is yes)
ask(user is vegetarian, "vegetarian_response")
function vegetarian_response(answer)
if (answer is yes)
feed_user(salad)
else
ask(user likes burgers, "burgers_response")
function burgers_response(answer)
if (answer is yes) then
feed_user(burger)
else
tell_user("Picky!")
Run Code Online (Sandbox Code Playgroud)
虽然翻译成前一个样式的if语句也不错,但是一旦涉及局部变量,循环,嵌套函数调用等,事情就变得非常复杂.
这是序列化延续变得至关重要的地方.
序列化的延续在JavaFlow,Cocoon(Rhink),Seaside,PLT Scheme,SICS中使用,非常适合处理业务工作流程,医疗诊断和(在我的情况下)文本冒险游戏.
是否有任何Lua和Pluto以这种方式利用其功能的示例(希望是开源!),使用continuation来简化异步环境中的逻辑?
continuations lua serialization asynchronous continuation-passing
作为OSS库的作者,我总是试图使我的东西符合CLS.但MS不会让这很容易.他们经常让你陷入困境22,如下所示:
我知道没有.NET语言不支持以下划线开头的变量,并且我已经在很多地方使用它们,其中变量需要对子类可见.
我已经厌倦了这些警告,而且我打算在我的30多个C#库上关闭汇编级别的CLS合规性.
关闭库的CLS合规性是否存在实际问题?任何真正的问题,这样做呢?
几十年来,微软已经发布了关于软件的不可听的指导,其编码的字节数不到5%.我找不到任何证据表明这种最佳实践对任何事情都有实际影响.
但是,要小心,我正在检查.
不,这不是这个问题的反面的重复:没有任何理由不将DLL标记为CLSCompliant?
我在这里寻找实际的结果和效果,而不是MS实习生的建议.
例如,如果IronPython,IronRuby或F#无法读取或写入以下划线开头的变量,那就会产生影响,尽管这只会导致用户子类化某些对象时出现问题.
如果语言或工具完全无法使用程序集,除非它被标记为符合CLS,现在这是一个大问题.
只是在我的asp.net 4 Web表单项目中处理图像上传器/缩放器.有没有人知道C#中用于调整上传图像大小的技术可以帮助那些小于所需最小尺寸的图像?
显然,如果调整大小,质量将是可疑的,所以有没有人找到一种方法可能创建一个大小合适的新图像,可能是纯白色,然后将原始图像放在白色背景的顶部?
谢谢
编辑 - 现在ImageResizer.net运行良好,但在图像较小时调整工作大小.有关详细信息,请参阅IrishChieftains以下评论:
最终编辑################
好吧,我发誓我昨晚尝试了这个并没有用,所以也许只需要一个干净的浏览器或VS2010重启,但对于任何有兴趣的人来说,这是我的最终解决方案.关键是scale=upscalecanvas:
int maxWidth = 400;
int maxHeight = 200;
ImageBuilder.Current.Build(saveLocation, saveLocation, new ResizeSettings("width=" + maxWidth + "&height=" + maxHeight + "&mode=pad&bgcolor=DDDDDD&anchor=middlecenter&scale=upscalecanvas"));
Run Code Online (Sandbox Code Playgroud)
无法评价ImageResizer.net足够高 - 伟大的计划
我们正在使用来自imageresizing.net的图像缩放器,并且看到了一些奇怪的行为.
当我们从流中读取图像然后调整图像大小时,我们无法再访问原始图像的属性.
以下代码将重现该问题.
static void Main(string[] args)
{
using(var httpPostedFileBaseImage = new FileStream(@"C:\test.jpg",FileMode.Open, FileAccess.Read, FileShare.Read))
{
using(var uploadedImage = Image.FromStream(httpPostedFileBaseImage))
{
Console.WriteLine(uploadedImage.Width);
var resizedImage = ImageBuilder.Current.Build(uploadedImage,
new ResizeSettings("width=110;height=83"));
Console.WriteLine(uploadedImage.Width);
}
}
}
Run Code Online (Sandbox Code Playgroud)
在ImageBuilder行之前,我们可以看到uploadedImage.Width很好,但之后会抛出异常:
System.ArgumentException was unhandled
HResult=-2147024809
Message=Parameter is not valid.
Source=System.Drawing
StackTrace:
at System.Drawing.Image.get_Width()
at ConsoleApplication6.Program.Main(String[] args) in C:\Users\Daniel\Desktop\ConsoleApplication6\ConsoleApplication6\Program.cs:line 25
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, …Run Code Online (Sandbox Code Playgroud) 我正在使用一个上传图像,获取流并使用imageresizer.net调整大小的函数,然后将流上传到Amazon S3.
现在我想拍一张本地照片并将其转换为流.(调整大小并上传到amazonS3).基本上,如何将图像转换为流.
这可能是一个简单的问题,无法在任何地方找到答案.
这是一些基本代码.
Public Shared Sub MoveToAmazon(strImg As String, SKU As String)
Dim fullImg As String = "C:\ImageLocation\" & strImg
Dim img As Image = Image.FromFile(fullImg)
'Here Im missing the code to convert it to a stream.
UploadImage(imgStream, SKU)
End Sub
Public Shared Sub UploadImage(imgStream As Stream, imgName As String)
Dim MainStream As Stream = New MemoryStream
Dim HomeStream As Stream = New MemoryStream
Dim SmallStream As Stream = New MemoryStream
Dim TinyStream As Stream = New MemoryStream …Run Code Online (Sandbox Code Playgroud) 我有一个简单的MVC2应用程序,它将文件从浏览器上传到MS SQL数据库作为图像blob.
然后我可以用以下结果返回结果:
public FileContentResult ShowPhoto(int id)
{
TemporaryImageUpload tempImageUpload = new TemporaryImageUpload();
tempImageUpload = _service.GetImageData(id) ?? null;
if (tempImageUpload != null)
{
byte[] byteArray = tempImageUpload.TempImageData;
return new FileContentResult (temp, "image/jpeg");
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
但是我希望将这些图像重新调整为缩略图和图库大小的视图.这个结果可以做到这一点吗?我一直在玩伟大的imageresizer.net,但似乎想要将图像存储在我想要避免的服务器上.有可能在飞行中这样做吗?
我需要保留原始文件,如果可能的话,不要将图像存储为服务器上的文件.
感谢您的任何指示!
我正在运行与非托管库交互的软件.这些库不能在不同的AppDomain中使用,也不能在加载时使用.
因此,新部署会导致失败.
在Azure网站上,是否有任何方法可以请求重新加载应用程序池,或者防止新进程在进程中发生?