When I run the code block below using a standalone build or from within the editor the resulting PNG images look perfect. When executed on an iPad or iPhone the resulting PNG has artifacts as if it was being compressed. I’m at a loss.
...
Texture2D image;
for(int i=0; i<Grid.UptPixelList.Count; i++){
image = new Texture2D(imageWidth, imageHeight, TextureFormat.ARGB32, false);
image.filterMode = FilterMode.Point;
pixelList = Grid.UptPixelList*;*
origin = Grid.OriginList*;*
foreach(UptPixel pixel in pixelList){
if(Mathf.FloorToInt(pixel.position.z - origin.z) < 0) continue; // Skip, we’ve gone underground.
image.SetPixel(Mathf.FloorToInt(pixel.position.x - origin.x + halfWidth), Mathf.FloorToInt(pixel.position.z - origin.z), pixel.color);
}
image.Apply();
File.WriteAllBytes(filename + Path.DirectorySeparatorChar + dirname + layerCounter + “.png”, image.EncodeToPNG());
Destroy(image);
layerCounter++;
}
…
1 Answer
1
So the problem was a simple one to solve. Basically the foreach loop going through “pixelList” in the code shown in the question above only writes to a subset of the pixels in the texture. I needed to initialize all pixels of the texture to clear before writing the pixels in the list.
The new code looks like this:
...
Texture2D image = new Texture2D(imageWidth, imageHeight, TextureFormat.ARGB32, false);
image.filterMode = FilterMode.Point;
for(int i=0; i<Grid.UptPixelList.Count; i++){
ClearImage(image, imageWidth, imageHeight);
pixelList = Grid.UptPixelList*;*
origin = Grid.OriginList*;*
foreach(UptPixel pixel in pixelList){
if(Mathf.FloorToInt(pixel.position.z - origin.z) < 0) continue; // Skip, we’ve gone underground.
image.SetPixel(Mathf.FloorToInt(pixel.position.x - origin.x + halfWidth), Mathf.FloorToInt(pixel.position.z - origin.z), pixel.color);
}
image.Apply();
File.WriteAllBytes(filename + Path.DirectorySeparatorChar + dirname + layerCounter + “.png”, image.EncodeToPNG());
layerCounter++;
}
Destroy(image);
…
Where ClearImage is:
void ClearImage(Texture2D image, int width, int height){
for(int x=0; x<width; x++){
for(int y=0; y<height; y++){
image.SetPixel(x,y,Color.clear);
}
}
image.Apply();
}
If you would display the image using GUI.DrawTexture etc, does it also have artefacts? Could you show us the images you generate?
– StatementI won't be able to do the GUI Texture test until Monday but for now here is the standalone and ios export of a simple red square for comparison. ![alt text][1] [9726-ios.png|9726] [1]: /storage/temp/9725-standalone.png
– crappygraphix