简体   繁体   English

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

[英]How to remove black background that comes after rotating bitmap?

How to remove black background that comes after rotating bitmap ?. 如何删除rotating bitmap后出现的黑色背景? I have tried different methods but none of them seems to work. 我尝试了不同的方法,但似乎都没有用。 Please help me find a way out! 请帮助我找到出路!

This is my code it produces 这是我产生的代码

这个 image: 图片:

<!-- 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();
                    }

You must use your bitmap object b.setHasAlpha(true); 您必须使用位图对象b.setHasAlpha(true); put that line of code right after you declare your bitmap. 在声明位图后立即添加该行代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM