- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以,
我正在使用 C++ 中的 DIRECTX API 并设计一个 Sprite 界面,该界面在父 RECT
中进行裁剪,例如 UI 窗口或其他 Sprite 或您拥有的东西。
这是因为,稍后,我将为 UI 窗口制作一个滚动功能。
我认为一张图片很适合展示我想要实现的目标。
为了进行裁剪计算,至少需要四个变量/结构(据我所知):
RECT
:“裁剪”边界D3DXIMAGE_INFO
:包含图片的宽高等信息RECT
:用于 LPD3DXSPRITE->Draw()
函数。基本上,应该绘制图像的哪一部分。这是完成“剪裁”的地方。现在,如果我向您展示我的整个界面及其内部工作原理以及它如何处理变量,我认为您会感到困惑。
所以,相反,
这段代码演示了我目前如何计算裁剪。
void ClippingCalculation(){
RECT parent_bounds, draw_rect;
D3DXVECTOR2 sprite_position; //Relative to parent rect
D3DXIMAGE_INFO img_info;
//Fill image info
D3DXGetImageInfoFromFile("image.png", &img_info); //Image is 100x100px
//Define the rects
SetRect(&parent_bounds, 0, 0, 200, 200);
SetRect(&draw_rect, 0, 0, img_info.Width, img_info.Height); //Draw the entire image by default
//Give it a position that makes a portion go out of parent bounds
sprite_position = D3DXVECTOR2(150, 150); // 3/4 of the entire image is out of bounds
//Check if completely within bounds
bool min_x = (sprite_position.x > parent_bounds.left),
min_y = (sprite_position.y > parent_bounds.top),
max_x = (sprite_position.x+img_info.Width < parent_bounds.right),
max_y = (sprite_position.y+img_info.Height < parent_bounds.bottom);
if(min_x && min_y && max_x && max_y)
return; //No clipping needs to be done
float delta_top = parent_bounds.top - sprite_position.y,
delta_left = parent_bounds.left - sprite_position.x,
delta_bottom = parent_bounds.bottom - sprite_position.y,
delta_right = parent_bounds.right - sprite_position.x;
//Check if completely outside bounds
bool out_left = (delta_left >= img_info.Width),
out_top = (delta_top >= img_info.Height),
out_bottom = (delta_bottom >= img_info.Height),
out_right = (delta_right >= img_info.Width);
if(out_left || out_top || out_bottom || out_right){
//No drawing needs to be done, it's not even visible
return; //No clipping
}
if(!min_x) draw_rect.left = delta_left;
if(!min_x) draw_rect.top = delta_top;
if(!max_x) draw_rect.right = delta_right;
if(!max_y) draw_rect.bottom = delta_bottom;
return;
}
最佳答案
剪辑 RECT 比这容易得多:
clipped_rect.left= MAX(rect_a.left, rect_b.left);
clipped_rect.right= MIN(rect_a.right, rect_b.right);
clipped_rect.top= MIN(rect_a.top, rect_b.top);
clipped_rect.bottom= MAX(rect_a.bottom, rect_b.bottom);
bool completely_clipped=
clipped_rect.left>=clipped_rect.right ||
clipped_rect.bottom>=clipped_rect.top
这假设 Y 随着您的上升而增加。应该很容易找到特定于平台的 MIN
和 MAX
的高性能版本。
关于c++ - 如何在父 RECT 中有效地执行图像剪辑?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9552003/
; template person (deftemplate person (slot name (type STRING)) (slot gender (type SYMBOL)(allowed-s
我正在尝试使用 AudioRecord 从麦克风录制一些音频。录音有效,但音量太大,而且我的剪报很糟糕。我尝试使用 AutomaticGainControl,但它在我的设备上不可用。有没有其他方法可以
我正在开发一个小应用程序,用户可以在其中用手指在屏幕上移动背景。 background-position 由手指的位置定义。 我用的是angular,所以我有这种标签: 在我的 Cont
拥有 ag-grid v8.20 的 ag-grid(Angular 组件) 不幸的是,如果上下文菜单大于网格,它会被剪裁: (截图应该在这里,但我不能上传它,imgur bug?) 有没有办法让上下
我需要从 ListBox 中浮出一些内容如 DataTemplate 中指定的那样对于 ListBox.ItemTemplate .我正在使用 RenderTransform但内容被剪掉了 ListB
我有这个作业(我是学生),在 CLIPS 中,但是我无法取得任何进展,尽管在谷歌上搜索并花了一些时间。 (clear) (deftemplate book (multislot surname
我正在尝试在具有圆形路径的图像上使用“剪辑路径”。我知道有可能使用 svg 剪辑路径,但我认为它不可能让它真正响应 - 所以我决定在图像下方的 div 上使用 svg 图形 - 但我仍然有移动 Vie
我正在尝试在具有圆形路径的图像上使用“剪辑路径”。我知道有可能使用 svg 剪辑路径,但我认为它不可能让它真正响应 - 所以我决定在图像下方的 div 上使用 svg 图形 - 但我仍然有移动 Vie
背景 我们有一个 TIME 数据类型的列来指示耗时。 问题 当我们尝试插入大于 24 的小时数时,例如“25:00:00”,MySQL 会将此值裁剪为“01:00:00”,这不是我们想要的。 尝试的解
基本上,我正在创建一个包含两个图像的 View 。图像一显示在占据 View 左上角的直角三角形中,图像二显示在占据 View 右下角的直角三角形中。 想象一下沿对角线切割正方形,结果的每一半中存在不
我目前正在为单页网站制作剪切路径: http://grafomantestsite3.be/ 如您所见,这适用于 chrome,但不适用于 firefox、opera 等。 我做了一个代码笔来说明我的
我的 CSS 文件中有一行: clip: rect(0 0 0 0); 我看到 clip 现在已贬值,所以我尝试使用 clip-path。 clip-path 的等价物是什么? 是吗: clip-pa
我有两个 div,子 div 在父 div 中。 div child 比他的 parent 大。所以我决定在 div 父级中放置一个滚动条,因为我可以更好地看到 div 子级的内容。 问题是现在我需要
我正在为全屏背景图像在 WordPress 中编写 CSS。为了摆脱左侧的黑色矩形(菜单/侧边栏),我使用了下面的 CSS。 它在 chrome、IE 和移动设备上运行良好,但在 mac/safa
我想制作一个用户程序,它提取元素 a,其中元素 b(由参数给定)作为列表中的一对。 比如,如果我将 c 作为参数并列出 ((c a) (c b) (d f) (d g)),结果应该是 'a' 'b';
我是 Android 新手,我有两张图片,一张是空图片,另一张是代表进度条的完整图片。 如何使用 canvas.drawBitmap 只绘制整个图像的一部分? 我不想每次都调整位图图像的大小。 最佳答
我调整了我的字符串的大小以最大限度地适应高度(1 行),以便截断任何过大的宽度(如在字形中间),lineBreakMode:UILineBreakModeClip 应该这样做。相反,文本似乎通过仅绘制
我使用的导航 Controller 略微偏离屏幕边缘。当我尝试为导航 Controller 框架之外的 subview 设置动画时,它们会被剪裁。我试过设置: navigationController
我正在尝试使用 CSS3 转换为 CSS clip 设置动画,但没有成功。图像只是剪辑而没有过渡。 我错过了什么? #clipped { position:absolute; widt
我有一个 UITextView 显示一些大小可以变化的动态内容。textview 不允许滚动,它的大小与内容无关。考虑到它的自动布局约束,例如, TextView 在 iphone5 和 iPhone
我是一名优秀的程序员,十分优秀!