2015-10-12 3 views
0
protected Bitmap createBufferedImageFromImageTransport() { 
    int k = 0, i = 0, j = 0; 
    int[] pixelData; 
    Canvas canvas; 
    Paint paint;   

    Bitmap newImage = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); 
    canvas = new Canvas(newImage); 
    paint = new Paint(Paint.ANTI_ALIAS_FLAG); 

    pixelData = imageTransport.getInt32PixelData(); 

    canvas.drawBitmap(pixelData, 0, width, 0, 0, width, height, false, null); 

    MainActivity.handler.sendEmptyMessage(1); 

    return newImage; 
} 

У меня есть функция для создания растрового изображения из данных пикселя. Но изображение большое, поэтому этот метод слишком медленный для моей программы. Я хочу сделать это с помощью OpenGL ES или быстрее. Не могли бы вы дать мне какое-либо предложение об этом или какой-либо выборке?Самый быстрый способ рисования растрового изображения

+1

Научиться использовать OpenGL и текстуры больше, чем может быть объяснено в SO перелива ответа (если у вас нет опыта работы с OpenGL), попробуйте прочитать руководство, как это. http://www.learnopengles.com/android-lesson-four-introducing-basic-texturing/ – Robadob

ответ

1

Попробуйте заблокировать данные растрового изображения, используйте указатели, чтобы вручную установить значения. Это быстрее.

public override void PaintPoint(Layer layer, Point position) 
    { 
     // Rasterise the pencil tool 

     // Assume it is square 

     // Check the pixel to be set is witin the bounds of the layer 

     // Set the tool size rect to the locate on of the point to be painted 
     m_toolArea.Location = position; 

     // Get the area to be painted 
     Rectangle areaToPaint = new Rectangle(); 
     areaToPaint = Rectangle.Intersect(layer.GetRectangle(), m_toolArea); 

     Bitmap bmp; 
     BitmapData data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); 
     int stride = data.Stride; 
     unsafe 
     { 
      byte* ptr = (byte*)data.Scan0; 
      // Check this is not a null area 
      if (!areaToPaint.IsEmpty) 
      { 
       // Go through the draw area and set the pixels as they should be 
       for (int y = areaToPaint.Top; y < areaToPaint.Bottom; y++) 
       { 
        for (int x = areaToPaint.Left; x < areaToPaint.Right; x++) 
        { 
         // layer.GetBitmap().SetPixel(x, y, m_colour); 
         ptr[(x * 3) + y * stride] = m_colour.B; 
         ptr[(x * 3) + y * stride + 1] = m_colour.G; 
         ptr[(x * 3) + y * stride + 2] = m_colour.R; 
        } 
       } 
      } 
     } 
     bmp.UnlockBits(data); 
    } 
Смежные вопросы