- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
根据文档 Bitmap createBitmap (Bitmap source, int x, int y, int width, int height, Matrix m, boolean filter)
方法:
Returns an immutable bitmap from subset of the source bitmap, transformed by the optional matrix. The new bitmap may be the same object as source, or a copy may have been made. It is initialized with the same density as the original bitmap. If the source bitmap is immutable and the requested subset is the same as the source bitmap itself, then the source bitmap is returned and no new bitmap is created.
我有一个将方向应用于现有位图的方法:
private Bitmap getOrientedPhoto(Bitmap bitmap, int orientation) {
int rotate = 0;
switch (orientation) {
case ORIENTATION_ROTATE_270:
rotate = 270;
break;
case ORIENTATION_ROTATE_180:
rotate = 180;
break;
case ORIENTATION_ROTATE_90:
rotate = 90;
break;
default:
return bitmap;
}
int w = bitmap.getWidth();
int h = bitmap.getHeight();
Matrix mtx = new Matrix();
mtx.postRotate(rotate);
return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true);
}
我在这里调用它:
Bitmap tmpPhoto = BitmapFactory.decodeFile(inputPhotoFile.getAbsolutePath(), tmpOpts);
Bitmap orientedPhoto = getOrientedPhoto(tmpPhoto, orientation);
我检查过 tmpPhoto
是不可变的,但 getOrientedPhoto()
仍然返回可变图像,它是 tmpPhoto 的副本。有谁知道如何在不创建新位图对象的情况下使用 Bitmap.createBitmap()
以及我的代码有什么问题?
最佳答案
似乎只是关于此方法的文档不明确。我在 Bitmap
crateBitmap()
方法中找到了这段代码:
// check if we can just return our argument unchanged
if (!source.isMutable() && x == 0 && y == 0 && width == source.getWidth() &&
height == source.getHeight() && (m == null || m.isIdentity())) {
return source;
}
这意味着源位图只有在不可变且不需要转换的情况下才会返回。
关于java - 为什么 Bitmap.createBitmap() 返回与源位图不同的可变位图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12511117/
我有一个线性布局(宽度 = 填充父级,基本上它填满了设备的整个宽度),它包含 2 个子布局。一个 width=fill_parent 的线性布局(让我们称之为 linear1),第二个是 width=
当我尝试调用 createBitmap 时出现 java.lang.NullPointerException。这是我的代码: board = Bitmap.createBitmap(handler.s
我加载我保存的位图的位数组。 (和 BITMAPINFOHEADER 结构)。 HBITMAP Filemanager::LoadNextImageFromMyFile(HANDLE file) {
在我的应用程序中,我正在从它的颜色代码创建一个位图,如下所示: int width=getImageWidth(); int height=getImageHeight(); int[] array=
这个问题在这里已经有了答案: android - out of memory exception when creating bitmap (9 个回答) 关闭 8 年前。 我试图解决 Androi
我正在使用此代码来压缩图像,但是此代码有时工作正常,但当图像超过 3-4 个时,它会出现内存不足错误。错误发生在 Bitmap.createBitmap 上。 请帮我解决这个问题。 public St
尝试将此 OpenCV java 代码转换为 C#。 OpenCV Android Background Subtraction 大部分时间都在工作,但我在这条线上绊倒了 bmp = Bitmap.c
这个问题在这里已经有了答案: Android View.getDrawingCache returns null, only null (10 个答案) 关闭 7 个月前。 如果我在按钮点击监听器中
我有一个问题,我正在编写缩放位图的代码并使用 Bitmap.createBitmap() 方法创建新的位图,该方法总是返回一个我无法识别的错误。请向我建议有关相同的任何解决方案。 错误堆栈: 02-2
我需要大位图 (6000x2000),所以我创建了一个: Bitmap.Config conf = Bitmap.Config.ARGB_4444; Bitmap bm = Bitmap.create
有时,当我尝试创建模糊位图时,我会收到“空指针异常”。 发生在这段代码中(我最近开始捕捉异常,所以至少它不会使应用程序崩溃): try { using (Bitmap.Config confi
根据文档 Bitmap createBitmap (Bitmap source, int x, int y, int width, int height, Matrix m, boolean filt
您好,我正在创建图像编辑应用程序,我正在为 Canvas 和 ImageView 创建位图 这里我在 imageView 中使用 385kb 尺寸为 2000x2000 的图像文件 这是图片 我的问题
我需要为我在 Direct2D 中处理的光线转换器创建一个像素数组的位图。但是,我无法理解如何使用 CreateBitmap功能。具体来说,我不确定 srcData 参数应该是什么。我很确定/希望它是
为什么会 Bitmap bmp; bmp = Bitmap.createBitmap( 100, 100, Config.RGB_565 ); 曾经返回过高度和宽度为 -1 的位图吗?我在文档中没有看
我正在尝试从 View 中获取位图,因为我想模糊该位图并将其用作后续 Activity 的背景。 Logcat 给我: NullPointerException at android.graphics
我有一个静态方法,它应该加载 strip 图像,并返回带有图像 strip 每个图 block 的 Bitmap[]。我使用了这样的方法,但在桌面 java 中使用 BufferedImages 取得
我想在 JNI 中使用这段代码,而不用返回到 Java。 我已经将位图操作转换为 JNI(感谢其他 stackoverflow 海报),但这看起来更复杂,因为我不明白如何调用构造函数。 Bitmap
我已经在 HTC Desire with Android 2.2 上测试了我的游戏。游戏是 2D 的,具有带有多个位图图像(帧)的自定义 Sprite 。使用方法 Bitmap.createBitma
我正在尝试在 Android 中扩展可缩放的图像查看器以并排使用两个图像。为此,我使用了 Bitmap.createBitmap(int, int, Bitmap.Config)。不幸的是,这似乎会使
我是一名优秀的程序员,十分优秀!