我有一段时间创建缩略图然后将它们转换为字节数组.我尝试了三种方法,并且我都遇到了3次错误.
第一个是使用Bitmap.GetThumbnailImage,我过去使用过,然后直接保存到Response.OutputStream
第二个是使用System.Drawing.Graphics和DrawImage().仍然没有去.
第三个是创建一个新的位图,传入旧的位图,并设置新的大小.同样的错误.
值不能为空.
参数名称:encoder
说明:执行当前Web请求期间发生未处理的异常.请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息.
异常详细信息:System.ArgumentNullException:Value不能为null.
参数名称:encoder
源错误:
在执行当前Web请求期间生成了未处理的异常.可以使用下面的异常堆栈跟踪来识别有关异常的起源和位置的信息.
堆栈跟踪:
[ArgumentNullException:值不能为null.
参数名称:encoder]
System.Drawing.Image.Save(Stream stream,ImageCodecInfo encoder,EncoderParameters encoderParams)+615244
这是我的方法的代码.也许有人会看到我做错了什么.如果你不确定GetThumbSize,它只是一个方法,它接受图像大小和最大拇指大小,然后计算实际大小,以保持纵横比.
public static System.Drawing.Image.GetThumbnailImageAbort thumbnailCallback = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
public static bool ThumbnailCallback()
{
return false;
}
/// <summary>
///
/// </summary>
/// <param name="image"></param>
/// <param name="size"></param>
/// <remarks>
/// This method will throw a AccessViolationException when the machine OS running the server code is windows 7.
/// </remarks>
/// <returns></returns>
public static byte[] CreateThumbnail(byte[] imageData, Size size)
{
using (MemoryStream inStream …Run Code Online (Sandbox Code Playgroud) 我正在构建这个ASP.NET网站项目,当我构建时(Ctrl-F5)Visual Studio 2008使用端口4730上的ASP.NET开发服务器运行网站.有没有办法让它在端口80上运行?
显然我在之前的帖子中提出了错误的问题.我有一个使用X.509证书保护的Web服务,作为安全的网站运行(https:// ..).我想使用公司的根CA颁发的客户端机器证书(也是X.509)来验证客户端机器是否有权使用该服务.为了做到这一点,我需要检查证书并寻找一些识别功能,并将其与存储在数据库中的值(可能是指纹?)相匹配.
这是我用来从本地证书商店获取证书的代码(直接从http://msdn.microsoft.com/en-us/magazine/cc163454.aspx获取):
public static class SecurityCertificate
{
private static X509Certificate2 _certificate = null;
public static X509Certificate2 Certificate
{
get { return _certificate; }
}
public static bool LoadCertificate()
{
// get thumbprint from app.config
string thumbPrint = Properties.Settings.Default.Thumbprint;
if ( string.IsNullOrEmpty( thumbPrint ) )
{
// if no thumbprint on file, user must select certificate to use
_certificate = PickCertificate( StoreLocation.LocalMachine, StoreName.My );
if ( null != _certificate )
{
// show certificate details dialog …Run Code Online (Sandbox Code Playgroud) 我有一个C++函数,需要在一段时间后调用,并重复此任务.你知道Win32或pthread中的任何内置函数或示例代码吗?
谢谢,
朱利安
public IEnumerable<SelectListItem> GetList(int? ID)
{
return from s in db.List
orderby s.Descript
select new SelectListItem
{
Text = s.Descript,
Value = s.ID.ToString(),
Selected = (s.ID == ID)
};
}
Run Code Online (Sandbox Code Playgroud)
我将上面的内容返回到视图并填充一个DropDownList.我想SelectListItem (0, "Please Select..")在返回到视图之前向上面的linq结果添加一个默认值.这可能吗?
我正在编写一个可以通过自定义URL启动的iPhone应用程序.所以,我覆盖 - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
要测试我的更改,我必须在模拟器中运行应用程序,然后退出并启动Safari.然后,我在地址栏中输入我的自定义URL以启动应用程序.
但每次我启动时,应用程序都会崩溃.我试图找出原因,但是当我设置断点并从主屏幕(而不是在XCode)启动应用程序时,它似乎没有附加.
我甚至尝试将NSLog语句放在handleOpenURL消息中,但它们不会打印到控制台.
我想我可以创建UIAlertViews但是......是的,哎呀.是否有其他方式连接到模拟器中的调试会话?
这是一个人为的例子,说明我们的很多类如何返回自己的二进制表示(由C++读取).
def to_binary(self):
'Return the binary representation as a string.'
data = []
# Binary version number.
data.append(struct.pack('<I', [2]))
# Image size.
data.append(struct.pack('<II', *self.image.size))
# Attribute count.
data.append(struct.pack('<I', len(self.attributes)))
# Attributes.
for attribute in self.attributes:
# Id.
data.append(struct.pack('<I', attribute.id))
# Type.
data.append(struct.pack('<H', attribute.type))
# Extra Type.
if attribute.type == 0:
data.append(struct.pack('<I', attribute.typeEx))
return ''.join(data)
Run Code Online (Sandbox Code Playgroud)
我不喜欢的事:
data.append(struct.pack(该行的独特部分分散注意力.'<')一遍又一遍地重复.''.join(data).我喜欢什么:
self.image.size是作为两个无符号整数写出来的.是否有更可读/ pythonic的方式来做到这一点?
Peekado.net中的DataReader 似乎没有方法.我希望能够在循环阅读器之前执行一些一次性处理,能够查看第一行中的数据而不会导致后续迭代跳过它会很好.完成此任务的最佳方法是什么?
我正在使用a SqlDataReader,但最好是实现尽可能通用(即适用于IDataReader或DbDataReader).
请注意,因为这是一个问题的地狱;-)
我想在C中使用模板函数进行泛型集合操作(如search,foreach等),同时保持编译器静态类型检查.当你使用像这个例子中的简单回调时,这是相当简单的:
#define MAKE_FOREACH(TYPE)\
void foreach_##TYPE (TYPE[n] array, int n, void(*f)(TYPE)) {\
for(int i = 0; i < n; i++) {\
f(array[i]);\
}\
}
Run Code Online (Sandbox Code Playgroud)
所以你可以这样做:
MAKE_FOREACH(int)
MAKE_FOREACH(float)
void intcallback(int x){
printf("got %d\n", x);
}
void floatcallback(float x){
printf("got %f\n", x);
}
int main(){
int[5] iarray = {1,2,3,4,5};
float[5] farray = {1.0,2.0,3.0,4.0,5.0};
foreach_int(iarray, 5, intcallback);
foreach_float(farray, 5, floatcallback);
}
Run Code Online (Sandbox Code Playgroud)
如果我想用返回类型实现回调,例如创建一个"map"函数,我可以这样做:
#define MAKE_MAP(TYPE, RTYPE)\
RTYPE* map_##TYPE (TYPE[n] array, int n, RTYPE(*f)(TYPE)) {\
RTYPE* result = (RTYPE*)malloc(sizeof(RTYPE)*n);\
for(int i = 0; i < …Run Code Online (Sandbox Code Playgroud) 如何使用Python通过代理发出HTTP请求?
我需要对以下代码做什么?
urllib.urlopen('http://www.google.com')
Run Code Online (Sandbox Code Playgroud)