Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

245
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda