- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我目前正在尝试从指定的起始坐标(这是我的问题所在)拍摄应用程序窗口的指定部分的快照。
Rectangle bounds = new Rectangle((this.Width/2)-400,(this.Height/2)-200, 800,400);
using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height, PixelFormat.Format32bppArgb))
{
using (Graphics graphics = Graphics.FromImage(bitmap))
{
IntPtr hdc = graphics.GetHdc();
PrintWindow(this.axS.Handle, hdc, 0);
graphics.ReleaseHdc(hdc);
graphics.Flush();
string file = "example.png";
bitmap.Save(file, ImageFormat.Png);
}
}
我正在尝试制作一种动态自适应方法来截取窗口中心的屏幕截图,即使在调整大小后也是如此。我不确定如何将 x
和 y
应用于屏幕截图作为屏幕截图的起点。尺寸将始终保持 800,400
,并且无论窗口大小如何,始终截取应用程序中心的屏幕截图。
每一次我尝试的尝试,位图都会截取 0 (+800), 0 (+400)
的屏幕截图,其中 0, 0
我需要更改。
Bitmap
有这个能力吗?如果没有,我可以使用什么其他方法?
最佳答案
您可以使用 SetViewportOrgEx
在 HDC 上设置原点。我发现窗口的标题栏偏离了中心点的计算,所以我也考虑到了这一点。
int x = (this.Width / 2) - 400;
int y = ((this.Height + SystemInformation.CaptionHeight) / 2) - 200;
Rectangle bounds = new Rectangle(x, y, 800, 400);
using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height, PixelFormat.Format32bppArgb))
{
using (Graphics graphics = Graphics.FromImage(bitmap))
{
IntPtr hdc = graphics.GetHdc();
POINT pt;
SetViewportOrgEx(hdc, -x, -y, out pt);
// rest as before
}
}
SetViewportOrgEx
和 POINT
的签名:
[DllImport("gdi32.dll")]
static extern bool SetViewportOrgEx(IntPtr hdc, int X, int Y, out POINT lpPoint);
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public int X;
public int Y;
public POINT(int x, int y)
{
this.X = x;
this.Y = y;
}
public static implicit operator System.Drawing.Point(POINT p)
{
return new System.Drawing.Point(p.X, p.Y);
}
public static implicit operator POINT(System.Drawing.Point p)
{
return new POINT(p.X, p.Y);
}
}
关于c# - 我将如何为我的应用程序窗口的一部分拍摄快照?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4029505/
我的一个页面上有一个 map 控件,我希望拍摄它的照片并将其显示在不同的屏幕上。有谁知道我怎样才能实现这一目标?该 map 位于 范围内. 最佳答案 您应该使用 WriteableBitmap 类的
我正在使用 Qt 4.5 和 qgraphicsscene/view 向用户显示视频。 我想提供一个“获取快照”按钮,我相信有一种非常简单的方法可以让我想到的一切都简单得多。 我怎样才能优雅地做到这一
使用以下代码拍摄 AGSMapView 的快照 此代码将设置 kEAGLDrawablePropertyRetainedBacking 属性,这是必需的,否则它将拍摄白色快照。 let layer =
我目前正在使用 direct X 用 c++ 编写游戏,目前有一个 vector 来存储绘制我所有的 Sprite 。我无法让子弹在 vector 中工作。子弹射了,但应该有 50 颗却只射出一颗 /
如何获取安卓手机的打印屏幕??我正在用 GPS 做一个应用程序。所以我无法使用模拟器拍摄打印照片。有没有应用程序可以做到这一点? 最佳答案 通过 USB 连接您的手机,转到 Eclipse 中的调试透
我有以下 JSON Firebase 数据库: { "fruits": { "apple": { "name": "Gala", "ur
我正在做一个项目,它应该获取 iPhone 中视频图标内的视频。任何人都可以通过提供链接或其他方式来帮助我吗?如有任何帮助,我们将不胜感激。 谢谢 最佳答案 这是不可能的,因为我们无法从一个应用程序内
如何链接到嵌入 Flash 视频的快照而不是实际的 Flash 视频,以减少网站的加载时间? 最佳答案 是的,事实上这是一种经常使用的方法。您从带有播放按钮覆盖层的图像开始。单击后,图像元素将替换为播
我正在用这个截取 avPlayer 的屏幕截图.. print(startTime) print(Float64(startTime)) var time: CMTime =
我试图从 nib 加载一个 View ,配置它,并拍摄它的快照,而不是将它添加到屏幕上: + (void)composeFromNibWithImage:(UIImage*)catImage comp
我正在制作一个 tvOS 应用程序,我希望它看起来与电影应用程序相似。因此我有一个 UICollectionView。现在我的单元格不仅仅是简单的 UIImageView,而是更复杂一些。 我仍然想要
Apple 建议从提交给应用商店的屏幕截图中裁剪掉状态栏。在预览版中手动执行此操作非常繁琐且容易出错。 是否有任何开发人员有任何最佳实践建议或自动化技术来加速此过程?目标是将 iPad 和/或 iPh
我所有的搜索都涉及更一般的 arc/sin/cos 用法或射击到鼠标位置。我希望用键盘瞄准并发射射弹,并且作为网络类(class)中的菜鸟做一个项目,我已经从头开始做了很多工作,但我陷入了困境。我当前
假设我有一个服务: public interface ICustomersService { IObservable Customers { get; } }
在我的 IOS 应用程序中,我正在截取 UIImageView 的屏幕截图。如附件照片所示,它非常完美。但是在这里,我采用了 UIImageView content mode aspect fit 。
我正在使用 WebRTC 在两个用户之间建立视频聊天。我想拍一张显示其中一个人的 localView View 。 这是我的类,它使用 configureLocalPreview 方法将视频流与 UI
EBS 文档指出: As an example, volumes that operate with 20 GB or less of modified data since their most r
import qualified Data.Vector as V import Control.Lens import Data.Vector.Lens v = V.fromList [V.from
我在我的应用程序中的“查看”按钮中有一个用于使用以下代码拍摄快照的按钮 open func takeScreenshot(_ shouldSave: Bool = true) -> UIImage?
我基本上是在尝试在我的 Activity 中捕获相对布局的屏幕截图并将其保存为 PNG 图像。然后我需要将它作为位图文件检索。我编写了一些代码来完成此操作,但遗憾的是屏幕截图未保存在我的设备上。 XM
我是一名优秀的程序员,十分优秀!