久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Android發布高分辨率圖像內存不足

Android post high res image running out of memory(Android發布高分辨率圖像內存不足)
本文介紹了Android發布高分辨率圖像內存不足的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

各位開發者好.

我正忙著讓 Android 從應用上傳圖片.
我也讓它工作了(代碼如下).
但是當我發送大圖像(10 兆像素)時,我的應用程序因內存不足異常而崩潰.
一個解決方案是使用壓縮,但如果我想發送完整尺寸的圖像怎么辦?
我想也許有流的東西,但我不熟悉流.也許 urlconnection 可能會有所幫助,但我真的不知道.

I'm busy for android to upload images from a app.
I also got it working (code will follow below).
But when i send large images (10 megapixels) my app crashes with an out-of-memory exception.
A solution for this is to use compression but what if i want to send the full size image?
I think perhaps something with a stream but i'm not familair with streams. Perhaps urlconnection might help to but i really have no idea.

我將文件名命名為 File[0 to 9999].jpg帶有圖像日期的 post 值稱為 Filedata我為 post 值 dropboxid 提供了一個 UID

I give the filename the name File[0 to 9999].jpg The post value with the image date is called Filedata I give a UID for the post value dropboxid

下面的代碼有效,但我很想解決阻止我發送高分辨率圖像的問題.

The code below works but i would love to solve my problem that prevents me from sending high res images.

親切的問候

try
{
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    bitmap.compress(CompressFormat.JPEG, 100, bos);
    byte[] data = bos.toByteArray();

    HttpPost postRequest = new HttpPost(URL_SEND);

    ByteArrayBody bab = new ByteArrayBody(data, "File" + pad(random.nextInt(9999) + 1) + ".jpg");
    MultipartEntity reqEntity = new multipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
    reqEntity.addPart("Filedata", bab);
    reqEntity.addPart("dropboxId", new StringBody(URLEncoder.encode(uid)));
    postRequest.setEntity(reqEntity);

    HttpResponse response = httpClient.execute(postRequest);
    BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
    String sResponse;
    StringBuilder s = new StringBuilder();

    while((sResponse = reader.readLine()) != null)
    {
        s = s.append(sResponse);
    }

    if(d) Log.i(E, "Send response:
" + s);
}
catch (Exception e)
{
    if(d) Log.e(E, "Error while sending: " + e.getMessage());
    return ERROR;
}

推薦答案

當使用 ByteArrayOutputStream 然后調用 #toByteArray() 你已經有效地加倍 JPEG 正在使用的內存量.ByteArrayOutputStream 使用編碼的 JPEG 保存一個內部數組,當您調用 #toByteArray() 時,它會分配一個 new 數組 &從內部緩沖區復制數據.

When using ByteArrayOutputStream and then calling #toByteArray() you've effectively doubled the amount of memory the JPEG is using. ByteArrayOutputStream keeps an internal array with the encoded JPEG and when you call #toByteArray() it allocates a new array & copies the data from the internal buffer.

考慮將大型位圖編碼為臨時文件 &使用 FileOutputStreamFileInputStream 對圖像進行編碼和發送.

Consider encoding large bitmaps to a temporary file & using FileOutputStream and FileInputStream to encode and send the image.

如果沒有上傳" - 你的應用程序很好"地存活了我假設的內存中的巨大位圖?

Without "uploading" - your app survives "nicely" with the just the huge bitmap in memory I assume?

FileBody

File img = new File(this is where you put the path of your image)
ContentBody cb = new FileBody(img, "File" + pad(random.nextInt(9999) + 1) + ".jpg", "image/jpg", null);
MultipartEntity reqEntity = new multipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("Filedata", cb);
reqEntity.addPart("dropboxId", new StringBody(URLEncoder.encode(uid)));

這篇關于Android發布高分辨率圖像內存不足的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數據庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 欧美在线一区二区三区 | 91免费版在线 | 久久亚洲综合 | 精品伊人久久 | www.天天操 | 精品视频国产 | 亚洲精品字幕 | 久久久九九九九 | 国产欧美精品一区 | 欧洲精品在线观看 | 亚洲一区二区在线播放 | 成人精品国产免费网站 | 国产精品久久久久影院色老大 | 亚洲一二三区av | 久久久高清 | 三级在线免费 | 国产视频一区二区 | 男人天堂网站 | 不卡一区 | 日本黄色大片免费 | 精精国产xxxx视频在线播放7 | 亚洲国产中文字幕 | 综合国产在线 | 日韩欧美视频免费在线观看 | 亚洲综合中文字幕在线观看 | 99在线精品视频 | 国产免费又黄又爽又刺激蜜月al | 国产精品精品视频一区二区三区 | 久久久精品国产 | 日本福利视频 | 在线亚州 | 国产成人精品一区二三区在线观看 | 精品国产一区二区三区久久狼黑人 | 亚洲成色777777在线观看影院 | 国产日韩欧美激情 | 日韩a v在线免费观看 | 国产农村一级国产农村 | 国产网站在线免费观看 | 日韩高清中文字幕 | 91久久精品国产91久久性色tv | 亚洲精品久久久久久一区二区 |