26. april 2010 - 09:45
Der er
3 kommentarer
Skaler billedet proportional
Hej Jeg har noget as3 kode her for mit baggrunds billede: function drawImage():void{ StageWidth = stage.stageWidth; StageHeight = stage.stageHeight; if(tileImage){ imageHolder.x = 0; imageHolder.y = topMargin; imageHolder.graphics.clear(); imageHolder.graphics.beginBitmapFill(image.bitmapData); imageHolder.graphics.drawRect(0, 0, StageWidth, (StageHeight-topMargin-bottomMargin)); imageHolder.graphics.endFill(); } if(fsBgImage){ maxWidth = StageWidth; maxHeight = (StageHeight-topMargin-bottomMargin); rawWidth = image.bitmapData.width; rawHeight = image.bitmapData.height; var MTRX:Matrix = new Matrix(); var scaleX:Number = maxWidth/rawWidth; var scaleY:Number = maxHeight/rawHeight; maxWidth = rawWidth * scaleX; maxHeight = rawHeight * scaleY; MTRX.scale(scaleX, scaleY); scaledImage = new BitmapData(maxWidth,maxHeight); scaledImage.draw(image.bitmapData, MTRX,null,null,null,true); imageHolder.x = 0; imageHolder.y = topMargin; imageHolder.graphics.clear(); imageHolder.graphics.beginBitmapFill(scaledImage); imageHolder.graphics.drawRect(0, 0, StageWidth, (StageHeight-topMargin-bottomMargin)); imageHolder.graphics.endFill(); tileImage = false; } Jeg vil nu gerne have til at når man gør vinduet mindre skal det skalere proportionalt? Nogen der kan hjælpe med det?
Annonceindlæg fra Kingston Technology
26. april 2010 - 10:25
#3
hele koden for baggrunden : if(useImageBackground){ if(tileImage){ if(altBgImage){ imageHolder.x = stage.stageWidth; imageHolder.y = stage.stageHeight; imageHolder.scaleX = scaleX imageHolder.graphics.clear(); imageHolder.graphics.beginBitmapFill(image.bitmapData); imageHolder.graphics.drawRect(0, 0, StageWidth, (StageHeight-topMargin-bottomMargin)); imageHolder.graphics.endFill(); } else{ altImageHolder.x = 0; altImageHolder.y = topMargin; altImageHolder.graphics.clear(); altImageHolder.graphics.beginBitmapFill(altImage.bitmapData); altImageHolder.graphics.drawRect(0, 0, StageWidth, (StageHeight-topMargin-bottomMargin)); altImageHolder.graphics.endFill(); } } if(fsBgImage){ if(altBgImage){ maxWidth = StageWidth; maxHeight = (StageHeight-topMargin-bottomMargin); rawWidth = image.bitmapData.width; rawHeight = image.bitmapData.height; var MTRX:Matrix = new Matrix(); var scaleX:Number = maxWidth/rawWidth; var scaleY:Number = maxHeight/rawHeight; maxWidth = rawWidth * scaleX; maxHeight = rawHeight * scaleY; MTRX.scale(scaleX, scaleY); scaledImage = new BitmapData(maxWidth,maxHeight); scaledImage.draw(image.bitmapData, MTRX,null,null,null,true); imageHolder.x = 0; imageHolder.y = topMargin; imageHolder.graphics.clear(); imageHolder.graphics.beginBitmapFill(scaledImage); imageHolder.graphics.drawRect(0, 0, StageWidth, (StageHeight-topMargin-bottomMargin)); imageHolder.graphics.endFill(); tileImage = false; } else{ maxWidth = StageWidth; maxHeight = (StageHeight-topMargin-bottomMargin); rawWidth = altImage.bitmapData.width; rawHeight = altImage.bitmapData.height; var MTRX2:Matrix = new Matrix(); var scaleX2:Number = maxWidth/rawWidth; var scaleY2:Number = maxHeight/rawHeight; maxWidth = rawWidth * scaleX2; maxHeight = rawHeight * scaleY2; MTRX2.scale(scaleX2, scaleY2); scaledImage = new BitmapData(maxWidth,maxHeight); scaledImage.draw(altImage.bitmapData, MTRX2,null,null,null,true); altImageHolder.x = 0; altImageHolder.y = topMargin; altImageHolder.graphics.clear(); altImageHolder.graphics.beginBitmapFill(scaledImage); altImageHolder.graphics.drawRect(0, 0, StageWidth, (StageHeight-topMargin-bottomMargin)); altImageHolder.graphics.endFill(); tileImage = false; } }