令人驚訝的團結,多年來唯一方式簡單規模實際PNG是使用非常真棒庫http://wiki.unity3d.com/index.php/TextureScale在Unity5中縮放PNG? - Bountie
實例下
如何擴展使用Unity5功能的PNG ?現在必須有新的UI等方式。
因此,縮放實際像素(如在Color[]
)或字面上是一個PNG文件,也許從網上下載。
(順便說一句,如果你是新來統一組織,Resize
通話無關,它只是改變數組的大小。)
public WebCamTexture wct;
public void UseFamousLibraryToScale()
{
// take the photo. scale down to 256
// also crop to a central-square
WebCamTexture wct;
int oldW = wct.width; // NOTE example code assumes wider than high
int oldH = wct.height;
Texture2D photo = new Texture2D(oldW, oldH,
TextureFormat.ARGB32, false);
//consider WaitForEndOfFrame() before GetPixels
photo.SetPixels(0,0,oldW,oldH, wct.GetPixels());
photo.Apply();
int newH = 256;
int newW = Mathf.FloorToInt(
((float)newH/(float)oldH) * oldW);
// use a famous Unity library to scale
TextureScale.Bilinear(photo, newW,newH);
// crop to central square 256.256
int startAcross = (newW - 256)/2;
Color[] pix = photo.GetPixels(startAcross,0, 256,256);
photo = new Texture2D(256,256, TextureFormat.ARGB32, false);
photo.SetPixels(pix);
photo.Apply();
demoImage.texture = photo;
// consider WriteAllBytes(
// Application.persistentDataPath+"p.png",
// photo.EncodeToPNG()); etc
}
只是順便說一句我突然想起我可能只是說說在這裏縮小比例(因爲您經常需要做一些事情來發布圖片,創建動態或其他任何內容)。我想,通常不需要放大圖片的大小;這是毫無意義的質量明智的。
賞金來了!
目前仍沒有在推廣使用Unity功能的PNG的方式建造,Wiki上的代碼的最佳方式,但它可能是可能的整合魔鬼或FreeImage的做縮放或操縱如果更高級的東西是需要的。 – Chris