2016-04-02 30 views
-2

我有一些視頻和圖片渲染在現有的圖像表演圖像中目標C

使用AVFoundation能夠集合視圖使用AVAssetImageGenerator捕捉來自iPhone的視頻和生成的縮略圖。在圖庫中顯示時應該區分它的視頻縮略圖。所以我需要通過繪製視頻符號(比如播放圖標)來轉換精確的圖像。

可能嗎?

+0

除了Objective C,您還使用了其他什麼工具/庫?沒有你對問題更精確的話,很難給出答案。 (否則我不如建議在透明紙上打印圖像並將它們放在彼此之上... – jotik

+0

使用AVFoundation可以使用AVAssetImageGenerator從iPhone捕獲視頻並生成縮略圖。在圖庫中顯示時應該區分它的視頻縮略圖。所以我需要通過繪製視頻符號(比如播放圖標)來轉換精確的圖像。 – shamly

+0

請將這個信息添加到您的問題並通過適當的標籤爲您的問題標籤。人們可能沒有時間閱讀所有評論。 – jotik

回答

0

您可以使用CoreGraphics來編輯圖像。

首先,創建一個UIImage與您想要編輯的圖像。然後,做這樣的事情:

UIImage *oldThumbnail; //set this to the original thumbnail image 
UIGraphicsBeginImageContext(oldThumbnail.size); 
[oldThumbnail drawInRect:CGRectMake(0, 0, oldThumbnail.size.width, oldThumbnail.size.height)]; 

/*Now there are two ways to draw the play symbol. 

One would be to have a pre-rendered play symbol that you load into a UIImage and draw with drawInRect */ 

UIImage *playSymbol = [UIImage imageNamed:"PlaySymbol.png"]; 
CGRect playSymbolRect; //I'll let you figure out calculating where you should draw the play symbol 
[playSymbol drawInRect: playSymbolRect]; 

//The other way would be to draw the play symbol directly using CoreGraphics calls. Start with this: 
CGContextRef context = UIGraphicsGetCurrentContext(); 

//now use CoreGraphics calls. I won't go over it here, butthe second answer to this questionmay be helpful.

//Once you have finished drawing your image, you can put it in a UIImage. 
UIImage *newThumbnail = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); //make sure you remember to do this :) 

現在你可以使用一個UIImageView新生成的縮略圖緩存,所以你不必重新渲染它的每一個時間等

+0

playSymbolRect座標應該是什麼? I – shamly

+0

這是爲了您根據幾何圖形和圖像座標進行計算。你可以使用'UIImage'的'size'屬性。例如,'playSymbol.size.width'或'playSymbol.size.height'。如果您想將播放按鈕置於中央,則可以對數值進行硬編碼(如果您打算始終使用相同尺寸的圖像),或者根據所涉及圖像的大小進行計算。 – WolfLink

+0

另外這可能有所幫助:https://developer.apple.com/library/ios/documentation/2DDrawing/Conceptual/DrawingPrintingiOS/GraphicsDrawingOverview/GraphicsDrawingOverview.html – WolfLink

0

這應該工作(你可能有位置和大小播放):

-(UIImage*)drawPlayButton:(UIImage*)image 
{ 
    UIImage *playButton = [UIImage imageNamed:@"playbutton.png"]; 
    UIGraphicsBeginImageContext(image.size); 
    [image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)]; 
    [playButton drawInRect:CGRectMake(image.size.width/2-playButton.size.width/2, image.size.height/2-playButton.size.height/2, playButton.size.width, playButton.size.height)]; 
    UIImage *result = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    return result; 
}