赞 | 8 |
VIP | 0 |
好人卡 | 0 |
积分 | 26 |
经验 | 0 |
最后登录 | 2022-11-7 |
在线时间 | 297 小时 |
Lv3.寻梦者
- 梦石
- 0
- 星屑
- 2585
- 在线时间
- 297 小时
- 注册时间
- 2021-5-4
- 帖子
- 101
|
5楼
楼主 |
发表于 2021-6-11 00:44:21
|
只看该作者
Bitmap.prototype.rotateHue = function(offset,bitmap) {
function rgbToHsl(r, g, b) {
var cmin = Math.min(r, g, b);
var cmax = Math.max(r, g, b);
var h = 0;
var s = 0;
var l = (cmin + cmax) / 2;
var delta = cmax - cmin;
if (delta > 0) {
if (r === cmax) {
h = 60 * (((g - b) / delta + 6) % 6);
} else if (g === cmax) {
h = 60 * ((b - r) / delta + 2);
} else {
h = 60 * ((r - g) / delta + 4);
}
s = delta / (255 - Math.abs(2 * l - 255));
}
return [h, s, l];
}
function hslToRgb(h, s, l) {
var c = (255 - Math.abs(2 * l - 255)) * s;
var x = c * (1 - Math.abs((h / 60) % 2 - 1));
var m = l - c / 2;
var cm = c + m;
var xm = x + m;
if (h < 60) {
return [cm, xm, m];
} else if (h < 120) {
return [xm, cm, m];
} else if (h < 180) {
return [m, cm, xm];
} else if (h < 240) {
return [m, xm, cm];
} else if (h < 300) {
return [xm, m, cm];
} else {
return [cm, m, xm];
}
}
if (offset && this.width > 0 && this.height > 0) {
offset = ((offset % 360) + 360) % 360;
console.log(offset);
var context = bitmap.context;
var imageData = context.getImageData(0, 0, this.width, this.height);
var pixels = imageData.data;
console.log(imageData)
for (var i = 0; i < pixels.length; i += 4) {
var hsl = rgbToHsl(pixels[i + 0], pixels[i + 1], pixels[i + 2]);
var h = hsl[0] + (hsl[0] + offset) % 360;
var s = hsl[1];
var l = hsl[2];
var rgb = hslToRgb(h, s, l);
pixels[i + 0] = rgb[0];
pixels[i + 1] = rgb[1];
pixels[i + 2] = rgb[2];
}
context.putImageData(imageData, 0, 0);
//this._setDirty();
}
};
Bitmap.prototype.rotateHue = function(offset,bitmap) {
function rgbToHsl(r, g, b) {
var cmin = Math.min(r, g, b);
var cmax = Math.max(r, g, b);
var h = 0;
var s = 0;
var l = (cmin + cmax) / 2;
var delta = cmax - cmin;
if (delta > 0) {
if (r === cmax) {
h = 60 * (((g - b) / delta + 6) % 6);
} else if (g === cmax) {
h = 60 * ((b - r) / delta + 2);
} else {
h = 60 * ((r - g) / delta + 4);
}
s = delta / (255 - Math.abs(2 * l - 255));
}
return [h, s, l];
}
function hslToRgb(h, s, l) {
var c = (255 - Math.abs(2 * l - 255)) * s;
var x = c * (1 - Math.abs((h / 60) % 2 - 1));
var m = l - c / 2;
var cm = c + m;
var xm = x + m;
if (h < 60) {
return [cm, xm, m];
} else if (h < 120) {
return [xm, cm, m];
} else if (h < 180) {
return [m, cm, xm];
} else if (h < 240) {
return [m, xm, cm];
} else if (h < 300) {
return [xm, m, cm];
} else {
return [cm, m, xm];
}
}
if (offset && this.width > 0 && this.height > 0) {
offset = ((offset % 360) + 360) % 360;
console.log(offset);
var context = bitmap.context;
var imageData = context.getImageData(0, 0, this.width, this.height);
var pixels = imageData.data;
console.log(imageData)
for (var i = 0; i < pixels.length; i += 4) {
var hsl = rgbToHsl(pixels[i + 0], pixels[i + 1], pixels[i + 2]);
var h = hsl[0] + (hsl[0] + offset) % 360;
var s = hsl[1];
var l = hsl[2];
var rgb = hslToRgb(h, s, l);
pixels[i + 0] = rgb[0];
pixels[i + 1] = rgb[1];
pixels[i + 2] = rgb[2];
}
context.putImageData(imageData, 0, 0);
//this._setDirty();
}
};
var bitmap=ImageManager.loadSvActor("actor");
bitmap.rotateHue(by,bitmap);
var bitmap=ImageManager.loadSvActor("actor");
bitmap.rotateHue(by,bitmap);
Bitmap.prototype.rotateHue = function(offset) 只能传一个参数所以我加了参数bitmap 如果没加 var context = this._context;是没data.
虽然可以改变颜色但是颜色怪怪的只能显示粉红色或者不断变换颜色直到粉红色 还有this._setDirty();是什么东西我在MV里面找不到Dirty()是有什么作用的
在MV里面loadBitmap 经过很多function才能到达bitmap.rotateHue.
ImageManager.loadSvActor = function(filename, hue) {
return this.loadBitmap('img/sv_actors/', filename, hue, false);
};
滤镜能单独用在bitmap里面吗 在文档里面没有写滤镜可以在什么下作用 请问下ColorFilter怎么用啊
https://developer.rpgmakerweb.com/rpg-maker-mz/ColorFilter.html#setHue
我是刚接触rpg maker 所以很多东西不太明白 谢谢了 |
|