2012-03-20 44 views
1

請hepl如果一些身體有相同的問題... 我有sqlite數據庫,在NSData中的圖像。我需要在UIWebView中插入圖像,但...圖像不顯示....圖片來自sqlite db和html在uiwebview

NSString *html = [NSString stringWithFormat: 
        @"<html> <head>" 
        @"<style> body { font-family:Verdana;font-size:13px;}</style>" 
        @"</head>" 
        @"<img src=\"%@\" />" 
        @"<br/>%@" 
        @"</body> </html>", datePicture,strDescription]] ; 

然後,我將其插入一個UIWebView:

[descripWebView loadHTMLString:html baseURL:nil]; 
+0

圖像的NSDate找到???你的意思是NSData? – 2012-03-20 09:22:03

+0

對不起..是的,我的意思是nsdata – 2012-03-20 09:36:15

回答

3

如果您datePictureUIImage類型,你可以用base64編碼圖像,並將其直接嵌入到HTML中。

NSString *html = [NSString stringWithFormat: 
        @"<html> <head>" 
        @"<style> body { font-family:Verdana;font-size:13px;}</style>" 
        @"</head>" 
        @"<img src=\"data:Image/jpeg;base64,%@\" />" 
        @"<br/>%@" 
        @"</body> </html>", 
     [QSStrings encodeBase64WithData:UIImageJPEGRepresentation((datePicture, 1.0)], 
     strDescription]; 

請注意,我用QSStrings做編碼,可以在QSUtilities on github

+0

非常感謝你!它幫助了我! – 2012-03-20 10:38:17