zoukankan      html  css  js  c++  java
  • 用UIWebView加载本地图片和gif图

    加载gif图:

     NSData *gif = [NSData dataWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"9" ofType:@"gif"]];

        // view生成

        [webView loadData:gif MIMEType:@"image/gif" textEncodingName:NULL baseURL:NULL];

    加载本地的图片:

     //加载本地的图片原理是使用webView加载html标签

      UIImage *selectedImage = [UIImage imageNamed:@"icon_VC6_boxStart"];

        NSString *stringImage = [self htmlForJPGImage:selectedImage];

        //构造内容

        NSString *contentImg = [NSString stringWithFormat:@"%@", stringImage];

        NSString *content =[NSString stringWithFormat:

                            @"<html> "

                            "<style type="text/css"> "

                            "<!-- "

                            "body{font-size:40pt;line-height:60pt;} "

                            "--> "

                            "</style> "

                            "<body> "

                            "%@ "

                            "</body> "

                            "</html>"

                            , contentImg];

        

        //让self.contentWebView加载content

        [webView loadHTMLString:content baseURL:nil];

    //编码图片

    - (NSString *)htmlForJPGImage:(UIImage *)image

    {

        NSData *imageData = UIImageJPEGRepresentation(image,1.0);

        NSString *str1=[NSString stringWithFormat:@"data:image/jpg;base64,%@",[imageData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed]];

        return [NSString stringWithFormat:@"<img src = "%@" />", str1];

    }

  • 相关阅读:
    服务器控件Repeater
    HeidiSQL无法连接Myql
    未在本地计算机上注册“Microsoft.ACE.OLEDB.12.0”提供程序搜索
    DISTINCT删除重复数据
    Makedown文件保存问题
    Makedown 本地图片问题
    vsftpd配置文件详解[转载]
    centos 本地yum源的搭建
    OpenOffice菜单乱码解决和linux下安装字体
    让secureCRT正确显示中文
  • 原文地址:https://www.cnblogs.com/Acee/p/5729275.html
Copyright © 2011-2022 走看看