簡體   English   中英

Google App Engine后端-Java數據模型-位圖

[英]Google App Engine Backend - Java Data Model - Bitmap

我正在編寫一個應用程序,該應用程序將允許用戶拍照,為其添加一些標題和說明,然后將其上傳到服務器。 該程序包(圖片+標題+說明)被命名為“禮物”。

我使用了Google的自動化后端引擎生成器,並添加了一個名為Gift的@Entity類,該類包含所有變量和一個構造函數,以在名為AppEngine的新項目中構建“禮物”。 (我遵循了以下Google教程: https : //developers.google.com/eclipse/docs/endpoints-addentities )。

我的問題基本上是,我該如何與以前位於應用程序主包中,現在位於AppEngine src文件夾中的“ Gift”類進行交互?

例如,以前,每當我想創建一個新的“ Gift”並將其上傳時,我都只是使用其構造函數實例化了一個新的“ Gift”。 現在,不可能做到這一點,因為Eclipse迫使我在自動生成的包(com.package.app.giftendpoit.model)中使用“ Gift”類。

新的Gift類(稱為Java數據模型)從以下幾行開始:

/**
 * Model definition for Gift.
 * This is the Java data model class that specifies how to parse/serialize
 * into the JSON that is transmitted over HTTP when working with the giftendpoint. 
 * @author Google, Inc.
 */

@SuppressWarnings("javadoc")
public final class Gift extends com.google.api.client.json.GenericJson {

@com.google.api.client.util.Key
private Bitmap bmp;

(...)

當我嘗試在應用程序上創建新的Gift並將其設置為Bitmap時,在Eclipse上收到以下錯誤消息:

Gift類型的setBmp(com.package.app.giftendpoint.model.Bitmap)方法不適用於參數(android.graphics.Bitmap)

這是原始Gift類的一部分,該類仍然存在於自動生成的AppEngine項目中,但不適用於我的應用程序:

@Entity
public class Gift {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
private String title;
private String description;
private Bitmap bmp;

public Gift(String title, String description, Bitmap bmp) {
    super();
    this.title = title;
    this.description = description;
    this.bmp = bmp;
}

//Getters & Setters (ie. SetBmp (Bitmap bitmap)...)

禮物的標題和描述設置沒有錯誤,但位圖沒有錯誤。 這是我用來執行此操作的代碼:

public class EndpointsTask extends AsyncTask<Context, Integer, Long> {
    protected Long doInBackground(Context... contexts) {

           Giftendpoint.Builder endpointBuilder = new  Giftendpoint.Builder(
          AndroidHttp.newCompatibleTransport(),
          new JacksonFactory(),
          new HttpRequestInitializer() {
          public void initialize(HttpRequest httpRequest) { }
          });
           Giftendpoint endpoint = CloudEndpointUtils.updateBuilder(
  endpointBuilder).build();
  try {
      gift = new Gift();
      gift.setTitle(title);
      gift.setDescription(description);
      gift.setBmp(bmp); // Error:The method setBmp(com.package.app.giftendpoint.model.Bitmap) in the type Gift is not applicable for the arguments (android.graphics.Bitmap)

      Gift result = endpoint.insertGift(gift).execute();
  } catch (IOException e) {
    e.printStackTrace();
  }
      return (long) 0;
    }
}

關於如何解決此問題的任何提示?

謝謝

好的,剛發現我應該使用Blob而不是位圖。 這是將圖像轉換為斑點的代碼:

    byte[] byteArray = getIntent().getByteArrayExtra("image");
    bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
    bmpBlob = Base64.encodeToString(byteArray, Base64.DEFAULT);

我還更新了實體,以使用Blob代替位圖。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM