2011-07-11 3 views
0

comment obtenir des données d'image à partir d'une image bitmap? J'ai cherché, mais je ne peux pas trouver une solutionBlackberry - obtenir des données d'image à partir de bitmap

int height=bmp.getHeight(); 

int width=bmp.getWidth(); 
int[] rgbdata = new int[width*height]; 
ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
DataOutputStream dos = new DataOutputStream(bos); 
//Graphics g = new Graphics(bmp); 
bmp.getARGB(rgbdata,0,width,0,0,width,height); 

for (int i = 0; i < rgbdata.length ; i++) { 
    if (rgbdata[i] != -1) 
    { 
     dos.writeInt(rgbdata[i]); 
     dos.flush(); 
    } 
} 
bos.flush(); 
+0

Pourquoi votre code à mi-chemin entre la question? –

Répondre

1

Essayez ceci:

PNGEncoder encoder = new PNGEncoder(bitmap, true); 
byte[] imageBytes = encoder.encode(true); 

Et pour EncodedImage du tableau d'octets:

EncodedImage fullImage = EncodedImage.createEncodedImage(imageBytes, 0, imageBytes.length); 
+0

qu'est ce que PNGEncoder? est-ce une classe? –

+0

Oui, désolé j'ai oublié de donner le lien. Voici le PNGEncoder: http://www.mobiyana.com/code/blackberry/PNGEncoder.java –

Questions connexes