这里的问题是我有一个x和y大小的显示窗口,我需要在窗口内显示一个没有任何滚动的图像,并保持4:3的宽高比.我有以下代码片段:
// Lock the current height, calculate new width of the canvas and scale the viewport.
// get width of the movie canvas
qreal width = canvas_->width();
// Find the height of the video
qreal height = (width/4.0) * 3;
// find original width and height for video to calculate scaling factor
qreal videoWidth = movieData_->GetWidth();
qreal videoHeight = movieData_->GetHeight();
// calculate scaling factor
qreal scaleFactorWidth = width/videoWidth;
qreal scaleFactorHeight = height/videoHeight;
Run Code Online (Sandbox Code Playgroud)
当然,通过使用高度或宽度作为"锚点",新图像将以这种方式或其他方式引起滚动(假设原始图像首先大于窗口).如何找到适合预定尺寸的宽高比4:3的尺寸?
编辑 我需要传递x和y的比例因子来进行缩放
canvas_->scale(scaleFactorWidth, scaleFactorHeight);
Run Code Online (Sandbox Code Playgroud) 有没有人知道如何保持UserControl的高度/宽度比1:1?
例如,如果"高度">"宽度","宽度"和"高度"具有相同的大小,反之亦然.
import Image
image = Image.open('images/original.jpg')
width = image.size[0]
height = image.size[1]
if width > height:
difference = width - height
offset = difference / 2
resize = (offset, 0, width - offset, height)
else:
difference = height - width
offset = difference / 2
resize = (0, offset, width, height - offset)
thumb = image.crop(resize).resize((200, 200), Image.ANTIALIAS)
thumb.save('thumb.jpg')
Run Code Online (Sandbox Code Playgroud)
这是我当前的缩略图生成脚本.它的工作方式是:
如果您的图像为400x300,并且您希望缩略图为100x100,则原始图像的左侧和右侧将需要50个像素.因此,将其调整为300x300.这使原始图像具有与新缩略图相同的纵横比.之后,它会将其缩小到所需的缩略图大小.
这样做的好处是:
如果你要将400x300图像缩小到100x100,它看起来会变暗.如果您从0x0坐标获取缩略图,您将获得图像的左上角.通常,图像的焦点是中心.
我希望能够为脚本提供任何宽高比的宽度/高度.例如,如果我想将400x300图像的大小调整为400x100,它应该从图像的左侧和右侧刮掉150px ...
我想不出办法做到这一点.有任何想法吗?
我正在编写一个程序,允许我通过他们的API将照片上传到TUMBLR,我已经上传了(感谢你们).
我在GUI的一侧放了一个'queueBox',它显示了图像名称,它们存储在QListWidget中.我把它放在我的Main Class'构造函数中:
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.setupUi(self)
self.queueBox.itemClicked.connect(self.displayPhoto)
Run Code Online (Sandbox Code Playgroud)
我有这个方法:
def displayPhoto(self, item):
tempName = (item.text())
print tempName
self.myLabel.setPixmap(QtGui.QPixmap(_fromUtf8(directory + '\\' + tempName)))
## self.myLabel.pixmap(QPixmap.scaled(aspectRatioMode = Qt.IgnoreAspectRatio))
## ^ ^ ^ What do I do with this? How do I set it to maintain aspect ratio?
## Currently it says ''NameError: global name 'Qt' is not defined''
Run Code Online (Sandbox Code Playgroud)
这成功地将图像绘制到myLabel,这是一个QLabel,然而,它是非常规模的,我有
self.myLabel.setScaledContents(True)
Run Code Online (Sandbox Code Playgroud)
在我的ui_mainWindow类中,如果我将其转换为False,它会修复缩放,但它只显示图像的一小部分,因为图像比QLabel大得多.我想要的是能够保持纵横比,所以它看起来不会缩放和可怕.
我发现了这个:http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qpixmap.html 它说如何使用它,但是我无法让它工作,如上面的代码所示在我的评论中.有谁知道如何使用它?如果是这样,你能给我一个例子吗,我试过搜索但是我得到的大部分结果都是用C++编写的例子,而不是python.
谢谢!
我发现Instagram有一个300*300的相机窗口?它是一个正方形,然后我试图用GPUImage制作相同的相机尺寸.所以我这样写:
primaryView = [GPUImageView alloc] initWithFrame:
CGRectMake(0,0,300,300)];//define a square view
//define a still camera
stillCamera = [[GPUImageStillCamera alloc]
initWithSessionPreset:AVCaptureSessionPreset640x480
cameraPosition:AVCaptureDevicePositionFront];
//make it portrait
stillCamera.outputImageOrientation = UIInterfaceOrientationPortrait;
//define a filter
filter = [[GPUImageFilter alloc] init];
//force the output to 300*300
[filter forceProcessingAtSize:((GPUImageView*)self.primaryView).sizeInPixels];
//set things up
[stillCamera addTarget: filter];
[filter addTarget: primaryView];
[stillCamera startCameraCapture];
Run Code Online (Sandbox Code Playgroud)
现在我真的得到一个方形视图..但是视图看起来很平坦,它完全失真,我认为它可能是宽高比有问题.然后我设置主视图的填充模式,如下所示:
[primaryView setFillMode:kGPUImageFillModePreserveAspectRatioAndFill];
Run Code Online (Sandbox Code Playgroud)
这个:
[primaryView setFillMode:kGPUImageFillModePreserveAspectRatio];
Run Code Online (Sandbox Code Playgroud)
这个:
[primaryView kGPUImageFillModeStretch];
Run Code Online (Sandbox Code Playgroud)
最后!没有这些工作..所以我缺少什么,任何一个,帮助.
我有一些autolayout问题.
我们有ViewController,它有根视图和子视图.子视图具有固定的宽高比.我需要在旋转时将父视图放在父视图中.chid视图也应该居中.就像在图片上:

我有这个代码:
- (void)viewDidLoad
{
[super viewDidLoad];
UIView * v = [UIView new];
v.backgroundColor = [UIColor redColor];
v.translatesAutoresizingMaskIntoConstraints = NO;
v.tag = 100;
[self.view addSubview:v];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[v]|"
options:0
metrics:nil
views:@{@"v":v}]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[v]|"
options:0
metrics:nil
views:@{@"v":v}]];
for (NSLayoutConstraint *c in self.view.constraints) {
[c setPriority:800];
}
NSLayoutConstraint *c = [NSLayoutConstraint constraintWithItem:v
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:v
attribute:NSLayoutAttributeWidth
multiplier:0.8
constant:0.];
[c setPriority:1000];
[v addConstraint:c];
c = [NSLayoutConstraint constraintWithItem:v
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeCenterY
multiplier:1
constant:0.];
[c setPriority:1000];
[self.view addConstraint:c];
c = [NSLayoutConstraint constraintWithItem:v …Run Code Online (Sandbox Code Playgroud) 我有一个视图,我需要放置一个UIImageView,我被告知将其放在一个矩形内,该矩形采用屏幕宽度,其高度小于宽度(固定大小).然而,我给出的图像或多或少是方形jpeg图像,因此想法是填充应包含图像的矩形的宽度,并以保持其纵横比的方式设置图像的高度.然后,我应该能够让用户垂直滚动图像以查看完整的图像.
我怎么能这样做?
提前致谢
编辑:我需要为具有不同大小的几个图像执行此操作,但这应该在视图中适合相同的矩形区域大小
我正在尝试使用带有Tree扩展名的dgrid来设置行的样式.为此,我使用了https://github.com/SitePen/dgrid/issues/380中建议的aspect.after,如果你不使用Tree扩展,它会很好用.
但是使用Tree扩展时,构造函数完成时会渲染网格,因此aspect.after无效.
我的代码是:
require([
'dojo/_base/declare',
'dgrid/OnDemandGrid',
'dgrid/Tree',
'dgrid/Keyboard',
'dgrid/Selection',
'dstore/Memory',
'dojo/aspect',
'dstore/Tree',
'dgrid/extensions/ColumnResizer',
'dojo/domReady!'
], function (declare,OnDemandGrid, tree, Keyboard, Selection, Memory,aspect,TreeStore,ColumnResizer) {
var dataStore = new (declare([ Memory, TreeStore ]))({ data: $jsonData });
var CustomGrid = declare([ OnDemandGrid, tree, Keyboard, Selection, ColumnResizer ]);
var columns = $jsonHeadTitles;
columns[0][0] = tree(columns[0][0]);
var grid = new CustomGrid({
className: 'dgrid-autoheight',
collection: dataStore.filter( { parent: 0 }),
columns: columns,
noDataMessage: 'Sin registros',
shouldExpand: function(){ return true; },
selectionMode: 'single',
cellNavigation: false,
formatterScope: …Run Code Online (Sandbox Code Playgroud) 关于3D的opengl投影矩阵有很多很棒的教程,但我没有做3D.我真的很难按照自己的喜好进行正交投影设置.
int width = 320; int height = 480;
我用这些设置创建了一个视图投影矩阵.
//eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz//
matrix view = (0, 0, -20, 0, 0, -1, 0, 1, 0);
matrix projection = (0, width, 0, height, 1, 100);
glViewport(0, width, 0, -height);
Run Code Online (Sandbox Code Playgroud)
创建此视图和投影矩阵并将它们传递给gpu后.
然后我创建了一个四边形,-1,-1 to 1, 1以便它的原点位于中心.
然后我为四边形制作一个比例矩阵,这样我就可以在屏幕上看到它.它呈现为一个完美的正方形,但当然glViewport或透视矩阵不应该是正方形.它应该是矩形的.
如何设置glViewport以及透视矩阵,以便我可以保持纵横比.
例如,我现在的宽高比是宽度/高度.如何将其与投影矩阵和glviewport一起使用?
@Reto可能是正确的,我正在推翻这个但是opengl应用程序界面对我来说有点棘手.
编辑 我画了一张图片,希望有助于澄清事情.
假设我希望我的视口为320x480像素.我想要两种不同的缩放模式,我可以选择.保持一个固定的高度,宽度将增加,以显示更多的水平视图或固定的宽度,增加的高度,以显示更多的垂直.
假设我设计了一个320x480左右的场景,我把所有东西都放在外面,我知道我想扩大宽度,但保持一个固定的高度.
如何使用我的纵横比的glViewport和正交投影矩阵实现这一目标?
我使用ffmpeg以类似于此的方式连接视频:
我的输入遇到了一个奇怪的错误
[Parsed_concat_0 @ 000000002a05bb80] Input link in10:v0 parameters (size 1280x720, SAR 2049:2048)
do not match the corresponding output link in0:v0 parameters (1280x720, SAR 1:1)
Run Code Online (Sandbox Code Playgroud)
根据我的研究,我需要使用setsar强制所有视频在我结束之前为1:1,但我不知道如何在我的过滤器中执行此操作.
aspect-ratio ×10
image ×2
ios ×2
python ×2
autolayout ×1
c ×1
c# ×1
dgrid ×1
dojo ×1
ffmpeg ×1
gpuimage ×1
height ×1
math ×1
objective-c ×1
opengl ×1
pyqt4 ×1
qlabel ×1
qpixmap ×1
qt4 ×1
resize ×1
thumbnails ×1
tree ×1
uiimageview ×1
uiscrollview ×1
uiview ×1
viewport ×1
wpf ×1