我在WP8中有一项任务
在WP8屏幕中用户点击(按钮左右?)时,我需要截取屏幕截图并发送到某个服务器
我发送成功但问题有时它不是将整个屏幕发送到我的服务器
这是我的代码:
private void LayoutRoot_MouseLeave(object sender, MouseEventArgs e)
{
TakeScreenShort();
} private void TakeScreenShort()
{
WriteableBitmap bmpCurrentScreenImage = new WriteableBitmap((int)this.ActualWidth, (int)this.ActualHeight);
bmpCurrentScreenImage.Render(LayoutRoot, new MatrixTransform());
bmpCurrentScreenImage.Invalidate();
byte[] bytearray = null;
using (MemoryStream ms = new MemoryStream())
{
WriteableBitmap wbitmp = new WriteableBitmap(bmpCurrentScreenImage);
wbitmp.SaveJpeg(ms, wbitmp.PixelWidth, wbitmp.PixelHeight, 0, 100);
ms.Seek(100, SeekOrigin.Current);
bytearray = ms.GetBuffer();
}
string str = Convert.ToBase64String(bytearray);
string json = JsonConvert.SerializeObject(new
{
id = 11544714,
img = str,
width = bmpCurrentScreenImage.PixelWidth,
height = bmpCurrentScreenImage.PixelHeight,
});
string url = "http://178.188.9.96/imageservice/image.php"; …Run Code Online (Sandbox Code Playgroud) 我正在创建一个Windows视频捕获应用程序,并使用DirectShow进行捕获.当每个帧进来时,我想将它作为原始RGB位图抓取到缓冲区中,此时我的代码将执行我需要的任何处理.
我一直在寻找类似于我想做的样本,在网上看到的每个地方,人们都建议使用IMediaDet和/或ISampleGrabber接口进行逐帧捕获.不幸的是,两者都被弃用,甚至不在最新版本的Windows SDK中.
在DirectShow中进行逐帧捕获的最佳(现代)方法是什么?如果没有,是否有一个不同的库我应该使用它会给我逐帧捕获?
我正在尝试将我的项目从Visual Studio 2010移植到Visual Studio 2012.在我的代码中,我有一些文件处理,如下所示:
auto fileDeleter = [](FILE* f) { fclose(f); };
unique_ptr<FILE, decltype(fileDeleter)> fMinute(
fopen(minuteLogName.c_str(), "w"), fileDeleter);
unique_ptr<FILE, decltype(fileDeleter)> fIndividual(
fopen(individualLogName.c_str(), "w"), fileDeleter);
if (!fMinute || !fIndividual) {
throw Exceptions::IOException("One of the log files failed to open",
__FUNCTION__);
}
Run Code Online (Sandbox Code Playgroud)
这在2010年没有任何问题,但在2012年它失败了条件:
错误C2678:二进制'!' :没有找到哪个运算符采用类型>'std :: unique_ptr <_Ty,_Dx>'的左手操作数(或者没有可接受的转换)
...
可能是'内置C++运算符!(bool)'
C++ 11标准指定unique_ptr有一个bool运算符,允许你像我上面那样进行快速检查.更奇怪的是,VS2012的unique_ptr定义有这样的运算符:
_OPERATOR_BOOL() const _NOEXCEPT
{ // test for non-null pointer
return (this->_Myptr != pointer() ? _CONVERTIBLE_TO_TRUE : 0);
}
Run Code Online (Sandbox Code Playgroud)
但是我在编译时遇到了这个错误.为什么?
是的,我可以只是使用ofstream,但这是重点.
我有一个线程,我想坐在循环中,直到我准备退出程序,此时我希望它突破循环并退出所以我可以调用std::thread::join它.在c ++ 03的时代,我只会使用一个受锁保护的bool来告诉线程什么时候退出.这次我以为我会利用新的原子库(特别是std::atomic_bool),但我遇到了麻烦.以下是我的测试用例:
#include <atomic>
#include <thread>
#include <cstdio>
using namespace std;
void setBool(atomic_bool& ab)
{
ab = true;
}
int main()
{
atomic_bool b;
b = false;
thread t(setBool, b);
t.join();
printf("Atomic bool value: %d\n", b.load());
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我尝试编译时,宣布thread t吐出这种怪异.错误的核心部分似乎是:
从'std :: atomic_bool'类型的右值开始无效初始化'std :: atomic_bool&'类型的非const引用
为什么我不能参考atomic_bool?我该怎么做呢?
绑定函数(使用Boost Bind)时是否存在任何性能影响(正面或负面)?
我想创建一个函数,它接受一个对象的可选引用,如果没有提供,则在函数的持续时间内创建一个函数,即
void Foo(Bar& b = Bar()) { /* stuff */ }
Run Code Online (Sandbox Code Playgroud)
当然,这是无效代码,因为在此上下文中Bar无法隐式转换为Bar引用.引用不能const,就像b函数内部的变异一样.
你可以通过使用右值参考来解决这个问题,即
void Foo(Bar&& b = Bar()) { /* stuff */ }
Run Code Online (Sandbox Code Playgroud)
这是rvalue引用的有效用法吗?调用者现在必须调用std::move他们的Bar参数,即使我无意清除传递Bar,通常是在传递rvalues时的情况.
c++ pass-by-reference rvalue-reference move-semantics default-arguments
我试图(徒劳地)使用OpenGL和NVIDIA的Cg着色器系统设置MRT,最终目的是推迟渲染。我已经成功为单个目标同时使用了着色器和“渲染到纹理”,但是当我尝试将一个对象渲染到多个渲染目标时,它在任何一个中都无法显示。
我以以下方式设置帧缓冲区对象:
// Initialize textures
// (I'll spare you the code since I've done that without issues)
// Initialize the FBO
glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glGenRenderbuffers(1, &depthBuff);
glBindRenderbuffer(GL_RENDERBUFFER, depthBuff);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
GL_RENDERBUFFER, depthBuff);
// -snip-
// Bind each texture we want to use to the FBO at rtNum
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + rtNum,
GL_TEXTURE_2D, tex->getID(), 0);
// Check to make sure we're good to go
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
throw Exceptions::GLException("Frame buffer object is not complete.", …Run Code Online (Sandbox Code Playgroud) 我正在为一个宠物项目编写解析器,出于教育目的,我想手工而不是使用解析器生成器。不幸的是,许多在线资源(以及我在大学上的编译器课程)都采用某种 LL(k) 语法。我不想保留语法因素,因为左递归非终结符,例如
E ::= E * E
| E / E
| E + E
| E - E
| ...
Run Code Online (Sandbox Code Playgroud)
这在类似野牛的解析器生成器中是可能的,这似乎大大简化了语法。
手动解析这种语法的最简单方法是什么?到目前为止,我的研究告诉我,由于这里解释的原因,递归下降不是一种选择,并且使用递归上升的 LR 解析可能是一个不错的选择,尽管有几个站点停下来提到它不直观。
在D中,可以使用scope,即,在堆栈上分配类
void foo()
{
scope example = new Bar();
}
Run Code Online (Sandbox Code Playgroud)
现在,如果类Foo具有类Bar作为成员,是否有任何方法可以Bar在内部存储Foo并使用Foola C++进行拆分?
我曾希望如此
import std.stdio;
class Foo {
this() { writeln("Foo"); }
~this() { writeln("~Foo"); }
scope Bar inside;
}
class Bar {
this() { writeln("Bar"); }
~this() { writeln("~Bar"); }
};
void main()
{
scope f = new Foo();
writeln("I'm a main!");
}
Run Code Online (Sandbox Code Playgroud)
会产生类似的东西
Bar
Foo
我是主角!
~Bar
~Foo
相反,我只能得到
Foo
我是主力!
〜富
看起来将类成员存储为垃圾收集引用而不是就地存储只是不必要地使堆布局复杂化而没有什么好处.什么是scope做在这种情况下,如果不指定举行Bar …
c++ ×5
c++11 ×3
archive ×1
atomic ×1
bitmap ×1
boost ×1
boost-bind ×1
c# ×1
cg ×1
d ×1
directshow ×1
framebuffer ×1
gcc ×1
grammar ×1
opengl ×1
parsing ×1
performance ×1
reference ×1
shader ×1
unique-ptr ×1
unix-ar ×1
v8 ×1
visual-c++ ×1
windows ×1