位图图像比较

发布于 2024-11-07 11:39:55 字数 754 浏览 0 评论 0原文

有没有办法查找该方法的实现/源代码? API 需要这个来比较两个图像,因为它不断覆盖原始图像,并且在多次将 imageview 转换为位图之后,图像看起来不再很好了。 http://developer.android.com/reference/android/graphics/Bitmap.html#sameAs(android.graphics.Bitmap)

我正在执行此方法从图像创建位图并设置它再次作为图像视图让用户编辑他的图片。

public static Bitmap getBitmap(ImageView imageView) {

    BitmapDrawable mDrawable =  (BitmapDrawable) imageView.getDrawable();

    Bitmap b = mDrawable.getBitmap();
    return b;
}

然而,经过多次保存并从数据库中检索它进行编辑后,图像变成了这样: 在此处输入图像描述

对此: 在此处输入图像描述

最后是: 在此处输入图像描述

所以我需要一种方法来检测图像是否尚未更改,以免重新保存字节该位图的数组到数据库。

Is there a way to look for the implementation/source code of this method? It's in API need this to compare two images because it keeps overwriting the original image and after several times of converting the imageview to a bitmap, the image doesn't look very nice anymore.
http://developer.android.com/reference/android/graphics/Bitmap.html#sameAs(android.graphics.Bitmap)

I am doing this method to create a bitmap from the image and setting it again as an imageview to let the user edit his picture.

public static Bitmap getBitmap(ImageView imageView) {

    BitmapDrawable mDrawable =  (BitmapDrawable) imageView.getDrawable();

    Bitmap b = mDrawable.getBitmap();
    return b;
}

However, after several times of saving and retrieving it from the database to edit it, the image turns from this: enter image description here

to this:
enter image description here

and then finally this:
enter image description here

So i need a way of detecting whether the image hasn't been changed for me not to resave the byte array of this bitmap to the database.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

债姬 2024-11-14 11:39:55

编辑(基于附加信息)

您可能将图像保存为 JPEG,这是一种有损格式。每次保存都会失去质量。如果您多次加载和保存图像,请使用 PNG 或保留带有图像文本的另一个副本 - 当您需要更新它时,请再次从原始版本开始。

旧答案:

它可能与sameAs无关,并且在其他地方你正在做一些改变图像的事情。

来源位于此处 https://android.googlesource.com

sameAs 是一个用 C 实现的 JNI 函数,您可以在这里找到它:
https://android.googlesource.com/platform/frameworks/base/+/master/core/jni/android/graphics/Bitmap.cpp" rel="nofollow noreferrer"> googlesource.com/platform/frameworks/base/+/master/core/jni/android/graphics/Bitmap.cpp

EDIT (based on additional info)

You are probably saving the image as a JPEG, which is a lossy format. Every time you save you will lose quality. If you are loading and saving the image multiple times, either use PNG or keep another copy with the text of the image with the text -- when you need to update it, start with the original again.

OLD ANSWER:

It probably has nothing to do with sameAs, and somewhere else you are doing something to change the image.

The source is here https://android.googlesource.com.

sameAs is a JNI function implemented in C, you can find it here:
https://android.googlesource.com/platform/frameworks/base/+/master/core/jni/android/graphics/Bitmap.cpp

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文