canvas背景色
『壹』 怎麼樣使得 canvas 做的動畫,變成網頁的背景
可以看看這個網頁 http://codingpixel.com/ 背景中有一條可用鍵盤控制的小蛇。
其實就是用設置 z-index 的方法,但是對於古老的瀏覽器可能支持不完全。
『貳』 HTML5 Canvas清除局部內容但不影響背景
雖然我沒用過canvas但是它應該也是常規的HTML的DOM,在它上邊試著用JS建立一個DIV,這樣就不會影響canvas內部的東西了吧。
『叄』 怎麼把Canvas的背景設置為透明
java swing中將組件的背景設置成透明的示例如下:
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.events.*;
public class Talpha {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
Canvas canvas = new Canvas(shell, SWT.NO_BACKGROUND);
//使用paintlistener,保證每次均重新繪制。
canvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
GC gc = e.gc;
//讀圖像
ImageData imageData = new ImageData("1.jpg");
//這里是建立從左到右的漸進Alpha。
byte[] alphaValues = new byte[imageData.height * imageData.width];
for (int j = 0; j < imageData.height; j++) {
for (int i = 0; i < imageData.width; i++) {
alphaValues[j * imageData.width + i] = (byte) (255 - 255
* i / imageData.width);
}
}
imageData.alphaData = alphaValues;
Image image = new Image(display, imageData);
//繪制
gc.drawImage(image,0,0);//關鍵點是這里設置背景顏色
}
});
FillLayout fillLayout = new FillLayout();
fillLayout.type = SWT.VERTICAL;
shell.setLayout(fillLayout);
shell.setSize(200, 600);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
『肆』 javascript中使用canvas能不能設置背景色
不能,圖片繪制在canvas之上就算透明,透明混合的也是原來canvas的底色,我記得canvas是可以設置背景色的
『伍』 HTML5用canvas做動畫,下面這樣背景就消失了
painting方法中的context聲明在draw 方法中。在執行painting的方法時context是undefined
『陸』 android中,如何用canvas繪制透明
第一種思路是通過對Bitmap進行操作,將Bitmap的像素值get到一個int[]數組里,因為在android里Bitmap通常是ARGB8888格式,所以最高位就是A通道的值,對齊進行改變後再新建一個Bitmap即可。
第二種思路是通過設置canvas的paint的透明度,然後通過canvas.drawBitmap()來改變View的透明度。
Paint .setAlpha(0);
『柒』 js中在canvas中加入一張背景怎麼讓背景滾動
<html>
<head>
<metacharset="utf-8"/>
<title>LScroll5.html</title>
<scripttype="text/javascript">
varLScroll={
img:null,
sc:null,
scx:null,
at:0,
flag:true,
loadImg:function(srcs,callback){
varmg=newImage();
mg.src=srcs;
mg.onload=function(){
callback(this);
};//callbackfunction
returnLScroll.img=mg;
},
init:function(srcs){
if(!document.body)
document.createElement('body');
if(!LScroll.sc){
varsc=document.createElement('canvas');
LScroll.scx=sc.getContext('2d');
varcallback=function(imgs){//afteronloadimagecanbedraw
sc.width=imgs.width/4;
sc.height=imgs.height;//notstyle.
sc.style.backgroundColor='black';
sc.style.border='solid1pxwhite';
document.body.style.backgroundColor='black';
document.body.style.textAlign='center';
document.body.appendChild(LScroll.sc=sc);
LScroll.draw(LScroll.sc,LScroll.scx);
};
LScroll.loadImg(srcs,callback);
}
},
draw:function(sc,scx){
scx.clearRect(0,0,sc.width,sc.height);
scx.save();
scx.beginPath();
switch(LScroll.flag){
casetrue:
if(-LScroll.at==LScroll.img.width-sc.width)
LScroll.flag=!LScroll.flag;
LScroll.at--;
break;
casefalse:
if(LScroll.at==0)
LScroll.flag=!LScroll.flag;
LScroll.at++;
}
scx.drawImage(LScroll.img,LScroll.at,0);
scx.restore();
setTimeout(function(){
LScroll.draw(sc,scx);
},10);
}
};
window.onload=function(){
LScroll.init('./Park.jpg');
};
</script>
</head>
<body>
</body>
</html>
『捌』 html5的canvas怎麼把背景變得完全透明
你沒加背景元素是白的需要你仔細調節代碼
『玖』 canvas html5可以製作網頁的背景嗎
我知道有兩個思路
一個是js畫好畫布後,js把背景圖的地址變成畫布的數據。比如回canvas的id是HB, 畫好後執行document.body.style.background = "url('"+HB.toDataURL()+"')";
另一個答是你說的直接把其它元素層疊在畫布上,只要畫布足夠大, canvas的style設成"position:absolute;z-index:-1"應該就行了。
『拾』 請問如何設置canvas的沒畫圖前的背景顏色
先設置Canvas.Brush.Color,然後Canvas.FillRect(全部大小),全部大小好象不能由Canvas自身得到,得從它的屬主,如控制項、窗體、點陣圖、列印機等。