Skip to content

Commit dc4b839

Browse files
author
xyl
committed
bug - 图片计算高度错误导致的图片展示比例压缩
1 parent 2e20530 commit dc4b839

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

LSYReader/LSYReader/Reader/Model/LSYChapterModel.m

+9-4
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,15 @@ -(void)parserEpubToDictionary
5151
[scanner scanUpToString:@"</img>" intoString:&img];
5252
NSString *imageString = [self.epubImagePath stringByAppendingPathComponent:img];
5353
UIImage *image = [UIImage imageWithContentsOfFile:imageString];
54-
CGSize size = CGSizeMake((ScreenSize.width-LeftSpacing-RightSpacing), (ScreenSize.width-LeftSpacing-RightSpacing)/(ScreenSize.height-TopSpacing-BottomSpacing)*image.size.width);
55-
if (size.height>(ScreenSize.height-TopSpacing-BottomSpacing-20)) {
56-
size.height = ScreenSize.height-TopSpacing-BottomSpacing-20
57-
;
54+
55+
CGFloat width = ScreenSize.width - LeftSpacing - RightSpacing;
56+
CGFloat height = ScreenSize.height - TopSpacing - BottomSpacing;
57+
CGFloat scale = image.size.width / width;
58+
CGFloat realHeight = image.size.height / scale;
59+
CGSize size = CGSizeMake(width, realHeight);
60+
61+
if (size.height > (height - 20)) {
62+
size.height = height - 20;
5863
}
5964
[array addObject:@{@"type":@"img",@"content":imageString?imageString:@"",@"width":@(size.width),@"height":@(size.height)}];
6065
//存储图片信息

0 commit comments

Comments
 (0)