- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我在 iPhone 5 上有一个 KineticJS 5.1.0 舞台。由于 iPhone 的屏幕尺寸,我的舞台限制为 320px x 320px。我捕获的图像是 1280px x 1280px。我希望能够在舞台上处理此图像而不会因收缩而降低质量。
这是原始图像(大版本:https://dl.dropboxusercontent.com/u/47067729/originalImage2.jpg):
这是当我将图像加载到舞台上时发生的情况:
图像看起来很奇怪,正如您在图像上看到的那样,内部有很多 strip 。
当我应用过滤器时,图像看起来像这样。
这不是它应该的样子。
我创建了一个 JsFiddle ( http://jsfiddle.net/confile/qhm7dn09/) 来显示这个问题
console.clear();
var imageObj = new Image();
var img = null;
var saveBtn = document.getElementById("save");
var resultImage = document.getElementById("resultImage");
var original = document.getElementById("original");
var downloadLink = document.getElementById("DownloadLink");
Kinetic.pixelRatio = 4;
stage = new Kinetic.Stage({
container: 'container',
width: 320,
height: 320
});
layer = new Kinetic.Layer();
img = new Kinetic.Image({
x: 0,
y: 0,
image: new Image()
});
layer.add(img);
stage.add(layer);
imageObj.onload = function() {
var tmpWidth = Math.floor(imageObj.width /2);
var w = Math.min(tmpWidth, 320);
var h = imageObj.height * w / imageObj.width;
img.setImage(this);
img.setWidth(w);
img.setHeight(h);
img.cache(); // 5.1.0
// img.setFilter(Kinetic.Filters.Shinny); // 4.5.2.
img.filters([Kinetic.Filters.Shinny]); // 5.1.0
layer.draw();
};
imageObj.crossOrigin = "anonymous";
var imageUrl = "https://dl.dropboxusercontent.com/u/47067729/originalImage2.jpg";
imageObj.src = imageUrl;
original.src = imageUrl;
saveBtn.onclick = function(evt) {
console.log("save");
var canvas = $(stage.getContent()).find('canvas').get(0);
console.log("canvas: "+canvas);
var dataURL = canvas.toDataURL('image/jpeg', 1.0);
resultImage.src = dataURL;
downloadLink.href = dataURL;
};
如何在不降低质量的情况下编辑比我的屏幕/舞台尺寸大得多的图像?
编辑:呈现给用户的舞台/ Canvas 仍然是某种预览。不应缩小原始图像。应用效果并导出舞台后,我希望导出的图像与原始图像大小相同,而不会降低质量。我不想将 320px x 320px 的舞台大小调整回 1280px x 1280px,这会导致巨大的质量损失。
最佳答案
在 iPhone 上看到的振铃模式是 resizing artifacts , 一种 Moiré pattern .是actually pretty common .
在撰写本文时,我们无法控制 Canvas 如何缩放图像,因此我们需要解决它:
使用更合适的 scaling algorithm 手动创建一个或多个缩放图像.目的是避免缩放,从而避免任何伪影。
实现 step down algorithm ,并在将其交给 Kinetic 之前生成更合适尺寸的图像。
在缩小比例之前对图像进行模糊处理会淡化伪像,但不会消除它。在 Kinetic 中,只需正常应用模糊滤镜即可。
实现一个更合适的scaling algorithm ,并使用它将图像动态缩放到维度(即自动 #1)。
当然,推荐前两种方法。
320 像素的舞台只会导出 320 像素的图像。要在不缩放的情况下以原始大小导出原始图像,您需要从足够大的舞台导出。新阶段不需要可见;这是off-screen rendering .
我已经修改了 fiddle 的保存处理程序来演示它:http://jsfiddle.net/qhm7dn09/13/embedded/result
请记住,JavaScript 的速度和效率远不及 native 程序,而且大多数移动设备在使用 JS 的浏览器中处理大图像时会遇到困难。
原始问题询问如何提高缩小后的图像质量。
鉴于现有的模糊滤镜,为 Kinetic 5.1 实现锐化滤镜相对容易。具体来说,是一个反锐化蒙版过滤器。
Kinetic.Filters.UnsharpMask = function kinetic_filter_unsharpmask( imageData ) {
var amount = this.attrs.unsharpAmout / 100; // Normally 1 to 100 (%)
var radius = Math.round( this.attrs.unsharpRadius );
var threshold = Math.round( this.attrs.unsharpThreshold ); // 1 to 765
if ( amount && radius > 0 && threshold > 0 ) {
var data = imageData.data, len = data.length, i;
// Copy the image and call blur filter on it
var blurData = new Uint8Array( imageData.data.buffer.slice(0) );
Kinetic.Filters.Blur.call(
{ blurRadius: function(){ return radius; } },
{ data: blurData, width: imageData.width, height: imageData.height } );
// Unsharp mask
for ( i = 0 ; i < len ; i += 4 ) {
// Calculate difference
var d = [ data[i] - blurData[i], data[i+1] - blurData[i+1], data[i+2] - blurData[i+2] ];
var diff = Math.abs( d[0] ) + Math.abs( d[1] ) + Math.abs( d[2] );
// Apply difference
if ( diff && diff >= threshold ) {
data[i ] = Math.max( 0, Math.min( Math.round( data[i ] + d[0] * amount ), 255 ) );
data[i+1] = Math.max( 0, Math.min( Math.round( data[i+1] + d[1] * amount ), 255 ) );
data[i+2] = Math.max( 0, Math.min( Math.round( data[i+2] + d[2] * amount ), 255 ) );
}
}
}
}
用法:
img = new Kinetic.Image({
x: 0, y: 0, image: imageObj,
unsharpRadius: 3, // Pixel range, should be integer (blur filter will round it to integer)
unsharpAmout: 50, // 1 to 100
unsharpThreshold: 10 // 1 to 765
});
img.filters([Kinetic.Filters.UnsharpMask]);
原问题还询问了渲染图像的感知差异,这不太可能是由不同的库引起的。
根据经验,这些因素通常会影响显示颜色的外观:
关于javascript - KineticJS:如何在不降低质量的情况下编辑比我的屏幕/舞台尺寸大得多的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26920982/
我使用透视滤镜在视频上放了一张图片。 示例 https://yadi.sk/i/MXtWUArJ3TyWBm 我怎样才能提高质量? 代码 ffmpeg -y -i bg.mp4 -loop 1 -i
我是 Matlab 的新手,虽然我知道一些其他的编程语言,所以如果这很简单,请原谅我。我无法在 StackOverflow 或其他地方找到任何答案。 我使用以下代码生成一个图形: figure(6)
我是 Matlab 的新手,虽然我知道一些其他的编程语言,所以如果这很简单,请原谅我。我无法在 StackOverflow 或其他地方找到任何答案。 我使用以下代码生成一个图形: figure(6)
在包含另一个类时,我总是需要写#include "headername.h"。是否可以在不编写其他类或使用“#include”包含多个类的情况下访问其他类? 最佳答案 什么 #include指令的作用
我有一个 .webm我想加速以延时拍摄的视频。我的原创.webm视频是 1280x720 并且质量非常好,但是当我用 FFMPEG 加速它时质量真的很差(即使分辨率保持不变)。这是我正在使用的命令:
我正在使用以下命令生成缩略图: mogrify -resize 128x128 -quality 75 "some thumb file" 对于示例文件: 如果我不指定质量 75,我会得到一个 40K
我想使用流体库的模型。谁能解释一下(我是建模/模拟的新手):质量/能量/动量平衡的公式:稳态、动态和初始猜测初始固定-->之间有什么区别以及对初始化时间/计算的影响是什么时间;我什么时候需要哪一个。
我通过解析“fmt 流映射”得到流 URL, 问题是如果我的视频时长不到 1 小时,我会得到这个: { "comment_count" = 1; description = ""; "dislikes
我试图根据用户的屏幕高度分辨率显示不同的视频分辨率,我有这段代码,但我不是 javascript 专家。它应该改变 src 属性,如果 res 低于 o 等于 360px 高度,等等。有什么建议吗?
我有播放 HLS 视频的 ExoPlayer,问题是我需要让用户能够更改视频质量(自动/1080/720/480)。 我发现使用 AdaptiveTrackSelection.Factory 确实可以
我的应用程序使用 phpmyadmin 连接到 mysql 中的数据库并将图像存储在数据库中,但我的问题是当我从数据库下载图像并将图像发布到 imageview 上时,图像的质量非常低颜色也受到影响。
大家好,我一直在使用 JavaFx 场景构建器来构建一个包含一些 png 图片的图形用户界面。 到目前为止,我一直在使用标签,然后将它们放大以适合图片(以便图片可见。但是这个解决方案并不令人满意,因为
我注意到,在显示比例为 1:1 的小图片时,它们通常看起来呈 block 状。我可以在使用 时解决问题通过使用更大比例的图像并使用 css 设置所需的大小来标记。 但是,我想用 background
我是自定义 CSS 的新手。我的老板希望我在 Qualtrics 中添加自定义 CSS(在外观/高级下)。在编辑预览窗口中,一切似乎都格式正确,但在实际调查页面上,许多元素的格式并未应用:图像是原始大
所以我尝试使用 CreateFont 尝试创建一种类似于我在 Photoshop 中使用的字体,但如果你仔细观察,Photoshop 中的质量要好得多。 这是我用来创建字体的代码: CreateFon
在自动去歪斜和裁剪之后我得到了下面的图像: 我需要对这张图片进行 OCR。现在 ABBYY Engine SDK 11 For Linux 产生的结果不是很好: IMerasers - www,rai
我目前在我的项目中使用 xorshift128+,我知道它通过了 Big Crush,并且被认为可以根据其速度生成相当高质量的随机数。但是,它会生成 64 位数字,而我需要的绝大多数随机数都是小整数(
我使用 python 以较小的质量保存 jpeg im = Image.open(file) im.save(cached_file, quality=80, optimize=True, progr
我在保存或使用 Gmagick PHP 扩展时找不到任何属性。 http://php.net/manual/en/book.gmagick.php 如何在 Gmagick 中更改 JPEG 质量? 最
youtube视频通常具有多种视频分辨率(质量),例如240p,360p,720p等,我如何检索youtube视频具有的视频分辨率(质量)是否有可以获取此信息的youtube api?Google.A
我是一名优秀的程序员,十分优秀!