2013-11-01 13 views
5

Hallo StackOverflow comunity. Ich brauche einige Informationen über die möglichen Methoden zum Teilen einer Bitmap in kleineren Stücken. Noch wichtiger, ich würde einige Optionen benötigen, um zu beurteilen. Ich habe viele Beiträge überprüft und bin immer noch nicht ganz überzeugt, was zu tun ist.Wie man eine Bitmap in Teile teilt, die auch Bitmaps sind

cut the portion of bitmap

How do I cut out the middle area of ​​the bitmap?

Diese beiden Verbindungen sind einige gute Möglichkeiten, fand ich, aber ich kann die CPU und RAM Kosten für jede Methode, oder vielleicht sollte ich nicht die Mühe mit dieser Berechnung überhaupt berechnen. Nichtsdestotrotz, wenn ich etwas tun möchte, warum nicht gleich von Anfang an.

Ich wäre dankbar, einige Tipps und Links auf Bitmap-Komprimierung zu bekommen, so dass ich vielleicht eine bessere Leistung durch Kombination der beiden Methoden bekomme.

Ich danke Ihnen im Voraus.

Antwort

3

Sie möchten eine Bitmap in Teile aufteilen. Ich nehme an, Sie möchten gleiche Teile aus bitmap.say schneiden, zum Beispiel benötigen Sie 4 gleiche Teile aus einer Bitmap.

Dies ist eine Methode, die eine Bitmap auf 4 gleiche Teile und hat es in einem Array von Bitmaps.

public Bitmap[] splitBitmap(Bitmap picture) 
{ 

Bitmap[] imgs = new Bitmap[4]; 
imgs[0] = Bitmap.createBitmap(picture, 0, 0, picture.getWidth()/2 , picture.getHeight()/2); 
imgs[1] = Bitmap.createBitmap(picture, picture.getWidth()/2, 0, picture.getWidth()/2, picture.getHeight()/2); 
imgs[2] = Bitmap.createBitmap(picture,0, picture.getHeight()/2, picture.getWidth()/2,picture.getHeight()/2); 
imgs[3] = Bitmap.createBitmap(picture, picture.getWidth()/2, picture.getHeight()/2, picture.getWidth()/2, picture.getHeight()/2); 

return imgs; 


} 
4

Mit dieser Funktion können Sie eine Bitmap in und die Anzahl der Zeilen und Spalten aufteilen.

Beispiel Bitmap [] [] bitmaps = splitBitmap (bmp, 2, 1); Erstellt eine vertikal geteilte Bitmap, die in einem zweidimensionalen Array gespeichert ist. 2 Spalten 1 Zeile

Beispiel Bitmap [] [] bitmaps = splitBitmap (bmp, 2, 2); Würde eine Bitmap in vier Bitmaps aufteilen, die in einem zweidimensionalen Array gespeichert sind. 2 Spalten 2 Zeilen

public Bitmap[][] splitBitmap(Bitmap bitmap, int xCount, int yCount) { 
    // Allocate a two dimensional array to hold the individual images. 
    Bitmap[][] bitmaps = new Bitmap[xCount][yCount]; 
    int width, height; 
    // Divide the original bitmap width by the desired vertical column count 
    width = bitmap.getWidth()/xCount; 
    // Divide the original bitmap height by the desired horizontal row count 
    height = bitmap.getHeight()/yCount; 
    // Loop the array and create bitmaps for each coordinate 
    for(int x = 0; x < xCount; ++x) { 
     for(int y = 0; y < yCount; ++y) { 
      // Create the sliced bitmap 
      bitmaps[x][y] = Bitmap.createBitmap(bitmap, x * width, y * height, width, height); 
     } 
    } 
    // Return the array 
    return bitmaps;  
} 
+1

Bei der Beantwortung sollten Sie versuchen, zu erklären, anstatt geben Sie nur ein Stück Code. – ThP

+0

Bitte beantworten Sie Ihre Antworten mit einem Text, der erklärt, was Sie in Zukunft tun. –

Verwandte Themen