Android -Setpixel, die schwarze Farbe zurückgeben
-
25-10-2019 - |
Frage
Ich habe die folgenden Funktionen:
private void clearScreen(int color)
{
fOffscreenImage.eraseColor(color);
}
private void fillRect(int x, int y, int width, int height, int color)
{
for(;x<width;x++)
{
for(;y<height;y++)
{
buffer[x+y*PROJECTIONPLANEWIDTH] = color;
}
}
}
private void drawBuffer()
{
fOffscreenImage.setPixels(buffer,0,PROJECTIONPLANEWIDTH,0,0,PROJECTIONPLANEWIDTH,PROJECTIONPLANEHEIGHT);
}
Beide Funktionen zeichnen zu einer Bitmap, zunächst erfolgt erasecolor, was gut funktioniert, und zweitens ist Setpixel, die immer schwarz zurückgibt. Ich schreibe das Bild einem Quad, das mit OpenGL angezeigt wird. Als Farbeingabe habe ich Standardfarben (color.blue) und color.argb ausprobiert. getPixel gibt die richtige Ausgabe der fraglichen Farben zurück.
A By Pixel Call bei SetPixel würde auch nicht funktionieren, er würde den Job ignorieren.
Ich werde mit Android 2.1 und 2.3 ausprobiert.
Alle Vorschläge dazu wären großartig.
Lösung 3
private void fillRect(int x, int y, int width, int height, int color)
{
width += x;
height += y;
for(;x<width;x++)
{
for(;y<height;y++)
{
buffer[x+y*PROJECTIONPLANEWIDTH] = color;
}
}
}
sollte sein
private void fillRect(int x, int y, int width, int height, int color)
{
width += x;
height += y;
for(int y2 = y;y2<height;y2++)
{
for(int x2 = x;x2<width;x2++)
{
buffer[x2+y2*PROJECTIONPLANEWIDTH] = color;
}
}
}
Andere Tipps
Ich habe einen Teil des Raycaster durch den folgenden FillRect -Code ersetzt und es zeigt jetzt weiße Zeilen an den entsprechenden Stellen! Jetzt nur um auch andere Farben herauszufinden :)
private void fillRect(int x, int y, int width, int height, int color)
{
width += x;
height += y;
for(;x<width;x++)
{
for(;y<height;y++)
{
if (x+y*PROJECTIONPLANEWIDTH < PROJECTIONPLANEHEIGHT*PROJECTIONPLANEWIDTH)
buffer[x+y*PROJECTIONPLANEWIDTH] = color;
}
}
}
Ich habe dies behoben, indem ich kein SetPixel verwendet habe, sondern stattdessen Leinwand zum Zeichnen zum Bitmap. Allerdings ist es tot.