Speichern Android SurfaceView, Bitmap und einige Elemente fehlen
Habe ich meine SurfaceView und mit einer Taste öffnen Sie die Kamera und nehmen Sie ein Bild, das als hintergrund verwendet und ein weiterer button zum hinzufügen von Elementen, die sitzen oben auf und können bewegt werden. Das alles funktioniert gut, bis ich versuchen zu retten, die SurfaceView als Bitmap, wenn alles, was ich bekommen ist der hintergrund und nichts von den Bildern an der Spitze.
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if(_mGotImage){
canvas.drawBitmap(_mImage, 0, 0, null);
}else{
canvas.drawColor(Color.BLACK);
}
//if the array is not empty
if(!_mJazzItems.isEmpty()){
//step through each item in the array
for(JazzItem item: _mJazzItems){
//get the bitmap it is using
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), item.getBitmap());
//and draw that bitmap at its X and Y coords
canvas.drawBitmap(bitmap, item.getX(), item.getY(), null);
}
}
}
Diese Methode wird aufgerufen, um zu versuchen, und speichern Sie die Leinwand.
public void screenGrab(){
Bitmap image = Bitmap.createBitmap(_mPanelWidth, _mPanelHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(image);
this.onDraw(canvas);
String path=Environment.getExternalStorageDirectory() + "/test2.png";
File file = new File(path);
try{
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
image.compress(CompressFormat.PNG, 100, ostream);
ostream.flush();
ostream.close();
}catch (Exception e){
e.printStackTrace();
}
}
Die onDraw-funktioniert einwandfrei, bekomme ich meine Kamera Schuss in den hintergrund und kann alle meine Artikel über die Spitze und bewegen Sie Sie. Nur wenn ich versuche einen Screenshot, keines der Elemente auf der Oberseite sind vorhanden.
Vielen Dank für jede Hilfe!!!!
-- UPDATE --
Habe ich geändert, die Standbild-Methode:
public void screenGrab(){
Bitmap image = Bitmap.createBitmap(_mPanelWidth, _mPanelHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(image);
canvas.drawBitmap(_mImage, 0, 0, null);
//if the array is not empty
if(!_mJazzItems.isEmpty()){
//step through each item in the array
for(JazzItem item: _mJazzItems){
//get the bitmap it is using
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), item.getBitmap());
//and draw that bitmap at its X and Y coords
canvas.drawBitmap(bitmap, item.getX(), item.getY(), null);
}
}
String path=Environment.getExternalStorageDirectory() + "/test2.png";
File file = new File(path);
try{
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
image.compress(CompressFormat.PNG, 100, ostream);
ostream.flush();
ostream.close();
}catch (Exception e){
e.printStackTrace();
}
}
Ich kann nicht sehen, warum dies ist keine Zeichnung der anderen Bilder über die top...
InformationsquelleAutor Scott Helme | 2012-05-24
Du musst angemeldet sein, um einen Kommentar abzugeben.
in meinem Fall bin ich mit diesem:
InformationsquelleAutor Zaz Gmy