如何在html页面中缩小图像大小?

时间:2022-02-24 21:16:45

I have one simple html with following code:

我有一个简单的html与以下代码:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="English">
    <head>
        <link href="../Styles/design.css" rel="stylesheet" type="text/css" />
        <title>Image</title>
        <style type="text/css">
            @page 
            {
                margin: 0; 
                padding: 0; 
            }
        </style>
    </head>

    <body style="margin: 0; padding: 0; oeb-column-number: 1;">
        <div style="width: 100%; height: 100%; margin: 0; padding: 0; text-align: center;"><img alt="main" id="mainImage" src="../images/Image.jpg" style="height: 100%; max-width: 100%; max-height: 100%; padding: 0; margin: 0;" /></div>
    </body>
</html>

In a folder I have Image.jpg file

在一个文件夹中,我有Image.jpg文件

Is that possible to add a css rule using Objective-C and change the img tag width and height? please help me.

是否可以使用Objective-C添加css规则并更改img标签的宽度和高度?请帮帮我。

I tried this code but it not working for me.

我试过这段代码,但它不适合我。

NSString *setImageRule = [NSString stringWithFormat:@"addCSSRule('img', 'max-width: %fpx; height: %fpx;')", self.webView.frame.size.width*0.75,self.webView.frame.size.height*0.75];
[webView stringByEvaluatingJavaScriptFromString:setImageRule];

1 个解决方案

#1


1  

if you want to resize the UIImage,you can simply access the folder where the image is stored and resize it. Use this code for example :

如果要调整UIImage的大小,可以只访问存储图像的文件夹并调整其大小。使用此代码示例:

+ (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
    //UIGraphicsBeginImageContext(newSize);
    UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
    [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();    
    UIGraphicsEndImageContext();
    return newImage;
}

#1


1  

if you want to resize the UIImage,you can simply access the folder where the image is stored and resize it. Use this code for example :

如果要调整UIImage的大小,可以只访问存储图像的文件夹并调整其大小。使用此代码示例:

+ (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
    //UIGraphicsBeginImageContext(newSize);
    UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
    [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();    
    UIGraphicsEndImageContext();
    return newImage;
}