Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change AVCaptureVideoPreviewLayer frame height and width

Please help me how to change the AVCaptureVideoPreviewLayer frame size and

I am passing Height =100px ; and width = 300px.

if i pass the height size 100 than width not change to 300px

Here is code :

    AVCaptureVideoPreviewLayer *previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:session];
    previewLayer.frame = CGRectMake(20, 50, 300, 100);
    self.view.frame=CGRectMake(20, 50, 300, 100);


    CGRect layerRect = [[[self view] layer] bounds];
    [previewLayer setBounds:layerRect];
    [previewLayer setPosition:CGPointMake(CGRectGetMidX(layerRect),CGRectGetMidY(layerRect))];
    [[[self view] layer] addSublayer:previewLayer];
    [previewView.layer addSublayer:previewLayer];
like image 662
Sandeep Sachan Avatar asked Aug 22 '13 13:08

Sandeep Sachan


1 Answers

@property (nonatomic, retain) AVCaptureVideoPreviewLayer *prevLayer;

Then:

self.prevLayer = [AVCaptureVideoPreviewLayer layerWithSession: self.captureSession];
    self.prevLayer.frame = yourRect;
[self.view.layer addSublayer: self.prevLayer];

Thats it.

like image 174
Krishna Kumar Avatar answered Oct 14 '22 20:10

Krishna Kumar