ios aygıtı ekranını yakalarken CAEmitterCells (bir CAEmitterLayer kullanılarak oluşturulan) yakalamanın bir yolu var mı?
UIGetScreenImage() çalışır, ancak özel bir yöntem olduğu için kullanmasına izin verilmez.
UIGraphicsBeginImageContext çalışmıyor gibi görünüyor, parçacıklar basitçe elde edilen görüntüden atlanır.iOS: ekranda CAEmitterLayer parçacıklarını yakalama
DÜZENLEME: Şu anda görünümü yakalamak için kullandığım kod. Ekranın 30 saniyelik bir videosunu, here adresinde aroth tarafından sağlanan kodu kullanarak kaydediyorum. Saniyenin 25 görüntüsünü (UIView alt sınıfı) ve alt görünümlerini (bizim katmanımızda CAEmitterLayer olan UIView dahil olmak üzere) saniyede kaydederek ve kayıt oluşturmak için AVAssetWriter'i kullanarak çalışır.
Oldukça ağız dolusu, bu yüzden ilgili satırları buraya yerleştireceğim: Kod XCode'daki ARC aracını kullanarak ARC'ye yazdım, bu nedenle kod biraz farklı bir bellek yönetimi olabilir.
- (CGContextRef) createBitmapContextOfSize:(CGSize) size {
CGContextRef context = NULL;
CGColorSpaceRef colorSpace;
int bitmapByteCount;
int bitmapBytesPerRow;
bitmapBytesPerRow = (size.width * 4);
bitmapByteCount = (bitmapBytesPerRow * size.height);
colorSpace = CGColorSpaceCreateDeviceRGB();
if (bitmapData != NULL) {
free(bitmapData);
}
bitmapData = malloc(bitmapByteCount);
if (bitmapData == NULL) {
fprintf (stderr, "Memory not allocated!");
return NULL;
}
context = CGBitmapContextCreate (bitmapData,
size.width,
size.height,
8, // bits per component
bitmapBytesPerRow,
colorSpace,
kCGImageAlphaNoneSkipFirst);
CGContextSetAllowsAntialiasing(context,NO);
if (context== NULL) {
free (bitmapData);
fprintf (stderr, "Context not created!");
return NULL;
}
CGColorSpaceRelease(colorSpace);
return context;
}
//static int frameCount = 0; //debugging
- (void) drawRect:(CGRect)rect {
NSDate* start = [NSDate date];
CGContextRef context = [self createBitmapContextOfSize:self.frame.size];
//not sure why this is necessary...image renders upside-down and mirrored
CGAffineTransform flipVertical = CGAffineTransformMake(1, 0, 0, -1, 0, self.frame.size.height);
CGContextConcatCTM(context, flipVertical);
[self.layer renderInContext:context];
CGImageRef cgImage = CGBitmapContextCreateImage(context);
UIImage* background = [UIImage imageWithCGImage: cgImage];
CGImageRelease(cgImage);
self.currentScreen = background;
//debugging
//if (frameCount < 40) {
// NSString* filename = [NSString stringWithFormat:@"Documents/frame_%d.png", frameCount];
// NSString* pngPath = [NSHomeDirectory() stringByAppendingPathComponent:filename];
// [UIImagePNGRepresentation(self.currentScreen) writeToFile: pngPath atomically: YES];
// frameCount++;
//}
//NOTE: to record a scrollview while it is scrolling you need to implement your UIScrollViewDelegate such that it calls
// 'setNeedsDisplay' on the ScreenCaptureView.
if (_recording) {
float millisElapsed = [[NSDate date] timeIntervalSinceDate:startedAt] * 1000.0;
[self writeVideoFrameAtTime:CMTimeMake((int)millisElapsed, 1000)];
}
float processingSeconds = [[NSDate date] timeIntervalSinceDate:start];
float delayRemaining = (1.0/self.frameRate) - processingSeconds;
CGContextRelease(context);
//redraw at the specified framerate
[self performSelector:@selector(setNeedsDisplay) withObject:nil afterDelay:delayRemaining > 0.0 ? delayRemaining : 0.01];
}
Bunun gerçekten yardımcı olacağını umuyorum. Desteğin için teşekkürler!
BTW - 'CGBitmapContextCreate() '__data__ param için NULL' ı geçebilir, bu durumda veriler otomatik olarak CG – nielsbot
tarafından tahsis edilir/dealloc'd olur, bende render kodunuzu göremiyorum Bu pasaj mı? – nielsbot
Bu sorunu çözebildiniz mi? –