如何使不改变位图尺寸位图COM preSS?位图、尺寸、preSS、COM

2023-09-12 01:11:42 作者:不再见不在

我用这个方法来COM preSS图片

I using this method to compress image

if(bitmapObject.compress(Bitmap.CompressFormat.PNG, 100, fOut))
{
    ... 
}

但是,这是COM preSS操作之前的形象,我得到的是很多小(维度)。

But that image that i get is much small ( in the dimension ) that was before the compress action.

我的应用程序需要发送的COM pressed图像通网络 - 所以我想发送的数据较少,我可以......但我必须保持图像的原始大小。

My application need to send the compressed image thru the network - so i want to send as less data as i can ... but i must to keep the original size of the image.

有没有跟上某些COM preSS原始位图维度一些其他的方式?

Is there some other way to keep the original bitmap dimension with some compress ?

推荐答案

你确定这是小?

Bitmap original = BitmapFactory.decodeStream(getAssets().open("1024x768.jpg"));
ByteArrayOutputStream out = new ByteArrayOutputStream();
original.compress(Bitmap.CompressFormat.PNG, 100, out);
Bitmap decoded = BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray()));

Log.e("Original   dimensions", original.getWidth()+" "+original.getHeight());
Log.e("Compressed dimensions", decoded.getWidth()+" "+decoded.getHeight());

给出

12-07 17:43:36.333: E/Original   dimensions(278): 1024 768
12-07 17:43:36.333: E/Compressed dimensions(278): 1024 768

也许你从资源获取位图,在这种情况下,位图的尺寸将取决于手机屏幕密度

Maybe you get your bitmap from a resource, in which case the bitmap dimension will depend on the phone screen density

Bitmap bitmap=((BitmapDrawable)getResources().getDrawable(R.drawable.img_1024x768)).getBitmap();
Log.e("Dimensions", bitmap.getWidth()+" "+bitmap.getHeight());

12-07 17:43:38.733: E/Dimensions(278): 768 576