- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的应用程序需要从磁盘读取 JPEG 文件,将其裁剪到已知区域,然后用不同的文件名保存。我当前的实现看起来像这样:
// open and crop the image
let image = CIImage(contentsOf: imagePath)
let cropRect = CGRect(x: 100, y: 100, width: 100, height: 100)
let croppedImage = image.cropped(to: cropRect)
// write to disk
let colorSpace = CGColorSpace(name: CGColorSpace.sRGB)
let context = CIContext()
context.writeJPEGRepresentation(of: croppedImage, to: destination, colorSpace: colorSpace, options: [kCGImageDestinationLossyCompressionQuality as CIImageRepresentationOption: 1])
我发现即使我通过裁剪边缘来减小图像的尺寸,保存的文件也最多是原始文件的两倍大。我认为这是因为我正在对其重新采样以另存为新的 JPEG。我还注意到图像略有不同 - 可能不那么清晰。我当然可以调整压缩质量以减小文件大小,但这同样会影响图像质量。
有没有办法只裁剪已经压缩的 jpeg 文件而不增加文件大小或改变其任何其他特征?
最佳答案
您的方法看起来是正确的。由于 JPEG 压缩的性质,您不能“只裁剪”图像而不在此过程中对其进行解码和重新编码。
较大的文件大小应该是由您选择的压缩质量造成的。引用文档:
A value of 1.0 specifies to use lossless compression if destination format supports it […]
1.0 质量的 JPEG 图像通常比 PNG 图像大。根据我的经验,介于 0.7 和 0.85 之间的值会产生良好的质量与尺寸平衡。
关于ios - 在不重新采样的情况下裁剪 JPEG 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56517873/
我正在寻找一种方法来对数字进行 1:40、3812 次(长度 = 3812)的采样,并进行替换 - 但对其进行限制,使每个数字的使用次数不会超过 100 次。有没有办法在采样命令 (sample())
如果我想随机采样 pandas 数据帧,我可以使用 pandas.DataFrame.sample . 假设我随机抽取 80% 的行。如何自动获取另外 20% 未选取的行? 最佳答案 正如 Lager
我使用以下函数在每个图像中采样点。如果batch_size为None,tf.range会给出错误。如何在 tensorflow 中采样 def sampling(binary_selection,nu
我想知道是否有任何方法可以循环浏览 .wav 文件以获取 wav 文件中特定点的振幅/DB。我现在正在将它读入一个字节数组,但这对我来说没有任何帮助。 我将它与我开发的一些硬件结合使用,这些硬件将光数
我有一个日期时间的时间序列,双列存储在 mySQL 中,并且希望每分钟对时间序列进行采样(即以一分钟为间隔提取最后一个值)。在一个 select 语句中是否有一种有效的方法来做到这一点? 蛮力方式将涉
我正在为延迟渲染管道准备好我的一个小型 DirectX 11.0 项目中的一切。但是,我在从像素着色器中对深度缓冲区进行采样时遇到了很多麻烦。 首先我定义深度纹理及其着色器资源 View :
问题出现在量子值的样本上。情况是: 有一个表支付(payments): id_user[int] sum [int] date[date] 例如, sum(数量) 可以是 0 到 100,000 之间
这是一个理论问题。我目前正在研究渲染方程,我不明白在哪种情况下区域采样或半球采样更好以及为什么。 我想知道的另一件事是,如果我们采用两种方法的平均值,结果是否会更好? 最佳答案 Veach 和 Gui
我有一个 4x4 阵列,想知道是否有办法从它的任何位置随机抽取一个 2x2 正方形,允许正方形在到达边缘时环绕。 例如: >> A = np.arange(16).reshape(4,-1) >> s
我想构建 HBase 表的行键空间的随机样本。 例如,我希望 HBase 中大约 1% 的键随机分布在整个表中。执行此操作的最佳方法是什么? 我想我可以编写一个 MapReduce 作业来处理所有数据
当像这样在 GLSL 中对纹理进行采样时: vec4 color = texture(mySampler, myCoords); 如果没有纹理绑定(bind)到 mySampler,颜色似乎总是 (0
我考虑过的一些方法: 继承自Model类 Sampled softmax in tensorflow keras 继承自Layers类 How can I use TensorFlow's sampl
我有表clients,其中包含id、name、company列。 表agreements,其中包含id、client_id、number、created_at列. 一对多关系。 我的查询: SELEC
在具有许多类的分类问题中,tensorflow 文档建议使用 sampled_softmax_loss通过一个简单的 softmax减少训练时间。 根据docs和 source (第 1180 行),
首先,我想从三个数据帧(每个 150 行)中随机抽取样本并连接结果。其次,我想尽可能多地重复这个过程。 对于第 1 部分,我使用以下函数: def get_sample(n_A, n_B, n_C):
我正在尝试编写几个像素着色器以应用于类似于 Photoshop 效果的图像。比如这个效果: http://www.geeks3d.com/20110428/shader-library-swirl-p
使用 Activity Monitor/Instruments/Shark 进行采样将显示充满 Python 解释器 C 函数的堆栈跟踪。如果能看到相应的 Python 符号名称,我会很有帮助。是否有
我正在使用GAPI API来访问Google Analytics(分析),而不是直接自己做(我知道有点懒...)。我看过类文件,但看不到任何用于检查采样的内置函数。我想知道使用它的人是否找到了一种方法
我正在尝试从 Peoplesoft 数据库中随机抽取总体样本。在线搜索使我认为 select 语句的 Sample 子句可能是我们使用的一个可行选项,但是我无法理解 Sample 子句如何确定返回的样
我有一个程序,在其中我只是打印到 csv,我想要每秒正好 100 个样本点,但我不知道从哪里开始或如何做!请帮忙! from datetime import datetime import panda
我是一名优秀的程序员,十分优秀!