我有一个位图,我想通过编码到base64发送到服务器,但我不想压缩png或jpeg中的图像.
现在我以前做的是.
ByteArrayOutputStream byteArrayBitmapStream = new ByteArrayOutputStream();
bitmapPicture.compress(Bitmap.CompressFormat.PNG, COMPRESSION_QUALITY, byteArrayBitmapStream);
byte[] b = byteArrayBitmapStream.toByteArray();
//then simple encoding to base64 and off to server
encodedImage = Base64.encodeToString(b, Base64.NO_WRAP);
Run Code Online (Sandbox Code Playgroud)
现在我只是不想使用任何压缩,也不想从位图中使用任何格式简单的byte [],我可以编码并发送到服务器.
有什么指针吗?
我从blob格式的数据库中获取图像.我想将它转换为Bitmap image.the我用来将位图转换为Blob的代码放在下面.但请告诉我如何反转它.???
ByteArrayOutputStream boas = new ByteArrayOutputStream();
btmap.compress(Bitmap.CompressFormat.JPEG, 100, boas ); //bm is the bitmap object
byte[] byteArrayImage = boas .toByteArray();
String encodedImage = Base64.encodeToString(byteArrayImage, Base64.DEFAULT);
Run Code Online (Sandbox Code Playgroud) 我是android的新手,我正在创建一个联系人管理器.我已经研究了如何将EditText字段中的值存储到数据库中,但我不知道如何在数据库中存储图像.我想知道是否有人可以帮助我.
package awad865.project.ContactManager1;
import java.io.FileNotFoundException;
import java.io.InputStream;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.database.SQLException;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Spinner;
public class AddContact extends Activity {
//declare private fields
private EditText firstName;
private EditText lastName;
private EditText number;
private EditText address;
private EditText date;
private EditText email;
private Spinner numberSpinner;
private Spinner emailSpinner;
private Spinner …Run Code Online (Sandbox Code Playgroud) 我仍然遇到BigDecimal的大问题(泪水的痕迹从这里开始,到目前为止一直持续到这里.
现在我遇到了相反的问题 - 从POJO中的BigDecimal到SQLite表中的REAL.
POJO定义为:
public class DeliveryItem {
private int _id;
private String _invoiceNumber;
private String _UPC_PLU;
private String _vendorItemId;
private int _packSize;
private String _description;
private BigDecimal _cost;
private BigDecimal _margin;
private BigDecimal _listPrice;
private int _departmentNumber;
private String _subdepartment;
private String _quantity;
public void setID(int id) {
this._id = id;
}
. . .
Run Code Online (Sandbox Code Playgroud)
这段代码,试图使数据形状能够发布到SQLite表(其中相应的列是数据类型REAL,SQLite唯一的实数/浮点数据类型):
public long addDeliveryItem(DeliveryItem delItem) {
long IdAdded = 0;
ContentValues values = new ContentValues();
values.put(COLUMN_INVOICENUM, delItem.get_invoiceNumber());
values.put(COLUMN_UPCPLU, delItem.get_UPC_PLU()); …Run Code Online (Sandbox Code Playgroud) 我已将位图图像转换为字符串以保存它:
............
Bitmap photo = extras.getParcelable("data");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
photo.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] b = baos.toByteArray();
String encodedImage = Base64.encodeToString(b, Base64.DEFAULT);
Run Code Online (Sandbox Code Playgroud)
然后我从字符串中检索位图以设置活动的背景,如下所示:
byte[] temp = Base64.decode(encodedImage, Base64.DEFAULT);
Options options = new BitmapFactory.Options();
options.inScaled = false;
Bitmap bitmap = BitmapFactory.decodeByteArray(temp, 0,
temp.length, options);
Drawable d = new BitmapDrawable(getResources(), bitmap);
getWindow().setBackgroundDrawable(d);
Run Code Online (Sandbox Code Playgroud)
一切正常,但图像质量大大降低.如何保持图像质量与原始图像相同?我在这里做错了什么,降低了质量?