2014-09-30 4 views
-1

나는 비트 맵 배열을 가지고있다. [photo1, photo2, photo3 .......] 배열에서 무작위 비트 맵을 사용하고 싶다. 나는 문자열로 비트 맵을 캐스팅하여 문자열로 사용할 수있다. 마지막 번호를 바꿨습니까? 또한 캐스팅 된 문자열 배열에서 비트 맵을 참조하는 싶습니다.비트 맵을 문자열로 변환하는 방법은 무엇입니까?

+0

시도해보십시오. - http://stackoverflow.com/questions/13562429/how-many-ways-to-convert-bitmap-to-string-and-vice-versa –

답변

0

이 시도 :이 도움이 Convert String to Bitmap and Bitmap to String

희망 :

String resultStr = convertBitmapToString (bmp1); 

public String convertBitmapToString(Bitmap bitmap){ 
    ByteArrayOutputStream baos=new ByteArrayOutputStream(); 
    bitmap.compress(Bitmap.CompressFormat.PNG,100, baos); 
    byte [] b = baos.toByteArray(); 
    String bString = Base64.encodeToString(b, Base64.DEFAULT); 
    return bString; 
} 

당신은 또한을 볼 수있다.

+0

빠른 질문 : 왜 이미지를 끈? :) –

+0

그/그녀가 물어 보는 질문이 아니야, 다시 질문을 읽고) * "비트 맵 배열이있어서 배열의 임의 비트 맵을 사용하고 싶다"* – m0skit0

+0

@ m0skit0 XY 문제처럼 보임 –

1

비트 맵을 문자열로 변환 할 수 없으며 가능한 경우에도 원하는 것을 이해하지 못합니다. 당신은 비트 맵의 ​​배열에서 임의의 비트 맵을 얻고 싶다면 다음과 같이 할 수있다 :

final Random rnd = new Random(); 
final int randomIndex = rnd.nextInt(array.length); 
final Bitmap randomBitmap = array[randomIndex]; 

PS를 : 자바 정말 대신 배열의 List의를 사용한다.

0

왜 배열의 색인을 나타 내기 위해 난수를 생성하지 않습니까?

Random rand = new Random(); 
int randomIndex = rand.nextInt(bitmaps.length); 
Bitmap randomBitmap = bitmaps[randomIndex]; 
0

나는 그가 사진 1, '사진이 ...

[사진 1,'사진, 사진 2 .......]

그는이 원하는되는지도와 비트 맵의 ​​이름이 생각 하나의 난수를 생성 한 다음 배열 (맵)에서 비트 맵을 가져 오는 메소드.

HashMap<String,Object> bitMaps= new HashMap<String,Object>(); 
... 
Random rand = new Random(); 
int randomIndex = rand.nextInt(bitMaps.size()); 
Bitmap randomBitmap = bitmaps.get("photo"+randomIndex) + 1; 

이 문제를 완전히 오해하면 죄송합니다.

관련 문제