Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

244
Vistas
How can I efficiently create a display bitmap of palletized colors in Android graphics?

My Android Tide app displays a nautical chart from a .KAP file. This file format uses a four bit palettized display system, only 10 colors are used. My app decodes the file format into an array of four bit colors. It displays a portion of this array onto the display as follows:

for (displayLineNum  = 1; displayLineNum < displayHeight; displayLineNum++)
{   for (displayDotNum = 1; displayDotNum < displayWidth; displayDotNum++)
   {  color = colors [lineIndex-1][dotIndex-1];  
      switch (color)
      {   case 1:  displayCanvas.drawPoint(displayDotNum, displayLineNum, color1); break;
          case 2:  displayCanvas.drawPoint(displayDotNum, displayLineNum, color2); break;
          case 3:  displayCanvas.drawPoint(displayDotNum, displayLineNum, color3); break;
          case 4:  displayCanvas.drawPoint(displayDotNum, displayLineNum, color4); break;
          case 5:  displayCanvas.drawPoint(displayDotNum, displayLineNum, color5); break;
          case 6:  displayCanvas.drawPoint(displayDotNum, displayLineNum, color6); break;
          case 7:  displayCanvas.drawPoint(displayDotNum, displayLineNum, color7); break;
          case 8:  displayCanvas.drawPoint(displayDotNum, displayLineNum, color8); break;
          case 9:  displayCanvas.drawPoint(displayDotNum, displayLineNum, color9); break;
          case 10: displayCanvas.drawPoint(displayDotNum, displayLineNum, color10); break;
          default: displayCanvas.drawPoint(displayDotNum, displayLineNum, color1); break;                    
      }
   }
}
display_area.setImageBitmap(displayBitmap);

There are 10 paint colors pre set with the RGB codes necessary for display. But each pixel has to be drawn individually with the displayCanvas.drawPoint function. This works but it is DOG SLOW. I would rather pre set the palette codes on the other side of the display call, and pass in the palette values instead. This would run a lot faster but I can't find a way to do this with the display calls available. There are Android functions to evaluate an image to get a palette for it, etc but I cant see how to efficiently display a palettized image. Each pixel is getting blown up for a four bit pixel code to a sixteen bit RGB565 code in order to pass in a normal bitmap. How else could I do this, thank you.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

To define the pixels of a Bitmap, you shouldn't use a Canvas because it adds an extra layer and is inefficient. You should deal with the Bitmap object directly. There are two ways to do that.

Calling setPixel

The setPixel() method allows to set the color of a pixel.

Example:

Bitmap bm = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
for(int x = 0; x < width; x++)
{
    for(int y = 0; y < height; y++)
        bm.setPixel(x, y, Color.BLUE);
}

Calling createBitmap

To avoid the overhead of calling setPixel() a large number of times, you can build an array with the pixel colors and pass it directly to createBitmap(). This is probably the most efficient way.

Example:

int length = width * height;
int[] colors = new int[length];
for(int i = 0; i < length; i++)
    colors[i] = Color.BLUE;
Bitmap bm = Bitmap.createBitmap(colors, width, height, Bitmap.Config.ARGB_8888);
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda