제 질문이 조금 바뀌 었습니다.비트 맵이 올바르게 저장되지 않았습니다 (Android 캔버스에서)
편집 :
// make textures from text
public static void createTextureFromText(GL10 gl, String text, String texName) {
Paint p = new Paint();
p.setColor(Color.GREEN);
p.setTextSize(32 * getResources().getDisplayMetrics().density);
// get width and height the text takes (in px)
int width = (int) p.measureText(text);
int height = (int) p.descent();
// Create an empty, mutable bitmap based on textsize
Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444);
// get a canvas to paint over the bitmap
Canvas canvas = new Canvas(bmp);
bmp.eraseColor(Color.CYAN); //Cyan for debugging purposes
//draw the text
canvas.drawText(text, 0, 0, p);
// save image - for debugging purposes
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 40, bytes);
// create a new file name "test.jpg" in sdcard
File f = new File(Environment.getExternalStorageDirectory() + File.separator + "test.jpg");
try {
f.createNewFile();
// write the bytes in file
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
fo.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
.... make texture
}
내가 지금 (이 단지 부분적으로) 주어진 텍스트에서 텍스처를 만들기위한 사용이 코드가 있습니다. 하지만 Bitmap 생성의 어딘가에 결함이 있다는 것을 알았습니다. 이제 비트 맵을 sd- 카드에 저장하여 모든 시안 비트 맵 (672B, 164x7이 치수 임)을 얻은 것을 확인했습니다. 그것은 텍스트가있는 비트 맵을 생성하지 않는 이유
은 누구나 볼 수 있습니까? 나는 무엇을 잘못 할 수 있습니까? 당신이 나를 도울 수 있다면 :)
는 나도 몰라,하지만 당신은 (화면에 표시하지 않고) 텍스트와 텍스트 뷰를 작성하는 경우에는, 해당 뷰를 측정하는 치수로 비트 맵을 만든 다음에 그릴을 사용할 수 있습니다 비트 맵으로 작성된 캔버스 (textview.draw (canvas)). 결국 텍스트에 꼭 맞는 비트 맵으로 끝날 것입니다. 나는 이것이 얼마나 효과적 일지에 관해 모른다. – Jave
textview는 사용자가 가지고있는 글꼴 크기/간격에 맞게 조정되므로 작동 할 수 있습니다. – Jave
http://developer.android.com/reference/android/graphics/Bitmap.html#eraseColor(int) -> "비트 맵의 픽셀을 지정된 색상으로 채 웁니다." – ethrbunny