如何删除旋转位图后出现的黑色背景?

问题描述 投票:0回答:1

如何删除rotating bitmap之后的黑色背景?我尝试了不同的方法,但似乎没有一种方法可行。请帮我找个出路! 这是我生成的代码

图片:

<!-- language: lang-java -->
         if (view.getId() == R.id.save_btn) {
                        emojiOn = false;
                        timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(new Date());
                        drawView.setDrawingCacheEnabled(true);
                        if (drawView.getDrawingCache() != null)
                            drawView.destroyDrawingCache();
                        drawView.buildDrawingCache();
                        AlertDialog.Builder saveDialog = new AlertDialog.Builder(this);
                        saveDialog.setTitle("Save drawing");
                        saveDialog.setMessage("Save drawing to device Gallery?");
                        saveDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {

                                Matrix matrix = new Matrix();
                                matrix.setRotate(Rotation);
                                Bitmap b = drawView.getDrawingCache();
                                b = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), matrix, true);

                                String imgSaved = MediaStore.Images.Media.insertImage(getContentResolver(), b, timeStamp, "drawing");

                                if (imgSaved != null)
                                    Toast.makeText(getApplicationContext(), "Drawing saved to gallery!", Toast.LENGTH_SHORT).show();
                                else
                                    Toast.makeText(getApplicationContext(), "Oops! Image could not be saved.", Toast.LENGTH_SHORT).show();
                                drawView.destroyDrawingCache();
                            }
                        });
                        saveDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();
                            }
                        });
                        saveDialog.show();
                    }
java android bitmap
1个回答
0
投票

您必须使用位图对象b.setHasAlpha(true);在声明位图后立即放置该行代码。

© www.soinside.com 2019 - 2024. All rights reserved.