void fade(ImagenBMP *imagen1, ImagenBMP *imagen2, int f) {
float v = (float)f/255;
for (int i = 0; i < imagen1->tamanyo; i++) {
imagen1->datos[i] = (imagen1->datos[i] - imagen2->datos[i])*v + imagen2->datos[i];
}}; //end of fade
它将两张图片淡化成一张图片。
答案 0 :(得分:1)
如果你改写等式,你最终会得到:
var backgroundMusicPlayer:AVAudioPlayer = AVAudioPlayer()
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewWillLayoutSubviews() {
var BGMusicURL:NSURL = NSBundle.mainBundle().URLForResource("BGMusicURL", withExtension: "mp3")
backgroundMusicPlayer = AVAudioPlayer(contentsOfURL: bgMusicURL, error: nil)
backgroundMusicPlayer.numberOfLoops = -1
backgroundMusicPlayer.prepareToPlay()
backgroundMusicPlayer.play()
}
这是混合的工作原理。您要指定在函数参数imagen1->datos[i] = v*imagen1->datos[i] + (1-v)*imagen2->datos[i];
中应包含多少第一张图像(255个部分中),f
部分将包含在第二张图像中。