与Android加工1920x1280的图像 - RenderScript [英] Processing 1920x1280 image with Android - RenderScript

查看:350
本文介绍了与Android加工1920x1280的图像 - RenderScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新手到renderScript并试图处理图像,大小1920x1280px,这似乎每次都崩溃与下面就logcat的误差

  09-04 19:26:04.670:D / dalvikvm(30308):GC_FOR_ALLOC释放73K,3%的自由6615K / 678​​7K,暂停26ms
09-04 19:26:04.680:I / dalvikvm堆(30308):成长堆(frag的情况下),以14.404MB为8294416字节分配
09-04 19:26:04.690:D / dalvikvm(30308):GC_CONCURRENT释放2K,免费2%14713K / 14919K,暂停1毫秒+ 1毫秒
09-04 19:26:04.820:D / dalvikvm(30308):GC_FOR_ALLOC释放0K,2%自由14713K / 14919K,暂停12毫秒
09-04 19:26:04.820:I / dalvikvm堆(30308):成长堆(frag的情况下),以17.917MB为3686416字节分配
09-04 19:26:04.840:D / dalvikvm(30308):GC_FOR_ALLOC释放0K,2%自由18313K / 18567K,暂停13毫秒
09-04 19:26:04.860:D / dalvikvm(30308):GC_CONCURRENT释放0K,免费2%18313K / 18567K,暂停1毫秒+ 2ms的
09-04 19:26:05.010:在0x5c41f809(code = 1)致命信号11(SIGSEGV):A / libc的(30308)
09-04 19:26:05.010:在0x5c41e001(code = 1)致命信号11(SIGSEGV):A / libc的(30308)

在那里,如果我调整图像大小相同的code工程100x56px: - (

请查看下面的code和建议我需要的任何更改将完成,code是基于我在别处找到在互联网上,并从样品的例子。

注:下面的code是不是真的生产质量

VDRender.rs的内容

 的#pragma版(1)
RS的#pragma java_package_name(com.iangclifton.tutorials.renderscript);#包括rs_graphics.rsh常量静态FLOAT3 gMonoMult = {0.299f,0.587f,0.114f};无效根(常量uchar4 * V_IN,uchar4 * V_OUT){    // rsDebug(称为root - ONE,rsUptimeMillis());    F4个float4 = rsUnpackColor8888(* V_IN);    FLOAT3单=点(f4.rgb,gMonoMult);
    * V_OUT = rsPackColorTo8888(单);
}

RenderScript101.rs含量

 的#pragma版(1)
RS的#pragma java_package_name(com.iangclifton.tutorials.renderscript);#包括rs_graphics.rshfloat4变量gBgColor; //背景色为XYZW 4部分组成的浮动
rs_allocation gBgImage; // 背景图
rs_allocation gVDBgImage; // 背景图rs_sampler gLinearClamp; //由程序片段用于采样
rs_program_fragment gSingleTextureFragmentProgram; //片段着色器
rs_program_store gProgramStoreBlendNone; //无融合,深度无程序商店
rs_program_vertex gProgramVertex; //默认的顶点着色器rs_script gVDScript;静态常量FLOAT3 gBgVertices [4] = {
    {-1.0,-1.0,-1.0},
    {1.0,-1.0,-1.0},
    {1.0,1.0,-1.0}
    {-1.0,1.0,-1.0}
};无效drawInteger(int值,诠释的x,int y)对{    字符文本[50] =0;
    INT索引= 0;    如果(值!= 0){    指数= 49;
    文[索引] = 0;    而(值大于0){        指数 -​​ ;        INT digitValue =值10%;        文[索引] ='0'+ digitValue;        值/ = 10;
    }    如果(值小于0){
        文[index--] =' - ';
    }
    }    rsgDrawText(安培;文[指数],X,Y);
}的int64_t gTimeMS = 0;
的int64_t updateFPS = 0;INT GFPS = 0;静态无效drawBackground(){    如果(gBgImage.p!= 0){        //rsgClearColor(gBgColor.x,gBgColor.y,gBgColor.z,gBgColor.w);        rs_matrix4x4投影,模型;
        rsMatrixLoadOrtho(安培;投影,-1.0F,1.0F,-1.0F,1.0F,0.0,1.0F);
        rsgProgramVertexLoadProjectionMatrix(安培;投影);        rsMatrixLoadIdentity(安培;模型);
        rsgProgramVertexLoadModelMatrix(安培;模型);        // ----
        如果(1)
        {
            rsForEach(gVDScript,gBgImage,gBgImage,NULL);
            rsgBindTexture(gSingleTextureFragmentProgram,0,gBgImage);
        }
        其他
        {
            rsgBindTexture(gSingleTextureFragmentProgram,0,gBgImage);
        }
        // ----        rsgDrawQuad(
            gBgVertices [0] .X,gBgVertices [0] .Y,gBgVertices [0] .Z,
            gBgVertices [1] .X,gBgVertices [1] .Y,gBgVertices [0] .Z,
            gBgVertices [2] .X,gBgVertices [2] .Y,gBgVertices [0] .Z,
            gBgVertices [3] .X,gBgVertices [3] .Y,gBgVertices [0] .Z
        );        INT X = 250;
        INT Y = 150;
        INT FPS = 0;        的int64_t T = rsUptimeMillis();
        INT差异= T - gTimeMS;
        FPS = 1000 /差异;
        gTimeMS = T;        如果((T - updateFPS)GT 500)
        {
            GFPS = FPS;
            updateFPS = T;
        }        rsgDrawText(FPS,X,Y);
        drawInteger(GFPS,250 + 40,150);
    }
}无效的init(){
    gBgColor =(float4变量){0.0,1.0F,0.0,1.0F};
    rsDebug(是init,rsUptimeMillis());
}INT根(){
    rsgBindProgramVertex(gProgramVertex);
    rsgBindProgramFragment(gSingleTextureFragmentProgram);
    rsgBindProgramStore(gProgramStoreBlendNone);    drawBackground();
    返回1;
}

RenderScript101RS.java的内容

 包com.iangclifton.tutorials.renderscript;进口android.content.res.Resources;
进口android.graphics.Bitmap;
进口android.renderscript.Allocation;
进口android.renderscript.Float4;
进口android.renderscript.Matrix4f;
进口android.renderscript.ProgramFragment;
进口android.renderscript.ProgramFragmentFixedFunction;
进口android.renderscript.ProgramStore;
进口android.renderscript.ProgramVertex;
进口android.renderscript.ProgramVertexFixedFunction;
进口android.renderscript.RenderScriptGL;
进口android.renderscript.Sampler;/ **
 *自定义RenderScript帮手,简化与RenderScript互动。
 *
 * @author伊恩·克利夫顿G.
 * /
公共类RenderScript101RS {    私人采样mLinearClamp;
    私人ProgramStore mProgramStoreBlendNone;
    私人ProgramVertex mProgramVertex;
    私人RenderScriptGL的mRS;
    私人ScriptC_RenderScript101 mScript;
    私人ScriptC_VDRender mVDScript;
    私人ProgramFragment mSingleTextureFragmentProgram;    / **
     *构造RenderScriptGL资源引用了新的帮手。
     *
     * @参数RS RenderScriptGL参考
     * @参数资源的资源参考
     * @参数渣油的int的renderScript(例如,R.raw.xyz)的ID
     * /
    公共RenderScript101RS(RenderScriptGL RS,资源RES,诠释渣油,诠释resId2){
        mRS评分= RS;        mScript =新ScriptC_RenderScript101(RS,资源,渣油);
        mVDScript =新ScriptC_VDRender(RS,资源,resId2);        mScript.set_gVDScript(mVDScript);        initProgramStore();
        initSampler();
        initProgramFragment();
        initProgramVertex();
        mRS.bindRootScript(mScript);    }    / **
     *设置在RenderScript查看自定义背景位图
     *
     * @参数位的位图作为背景使用
     * /
    公共无效setBackgroundBitmap(位图位图){
        如果(位图== NULL){
            返回;
        }
        最终分配bitmapAllocation = Allocation.createFromBitmap(MRS,位图,Allocation.MipmapControl.MIPMAP_NONE,Allocation.USAGE_GRAPHICS_TEXTURE);
        mScript.set_gBgImage(bitmapAllocation);        //最终分配bitmapVDAllocation = Allocation.createFromBitmap(MRS,位图,Allocation.MipmapControl.MIPMAP_NONE,Allocation.USAGE_GRAPHICS_TEXTURE);
        //mScript.set_gVDBgImage(bitmapVDAllocation);
    }    / **
     *设置在RenderScript视图自定义背景色
     *
     * @参数颜色FLOAT4颜色
     * /
    公共无效setBackgroundColor(FLOAT4颜色){
        mScript.set_gBgColor(颜色);
    }    / **
     * prepares的ProgramFragment(片段着色器)
     * /
    私人无效initProgramFragment(){
        最后ProgramFragmentFixedFunction.Builder pfBuilder =新ProgramFragmentFixedFunction.Builder(MRS);
        pfBuilder.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE,ProgramFragmentFixedFunction.Builder.Format.RGBA,0);
        mSingleTextureFragmentProgram = pfBuilder.create();
        mScript.set_gSingleTextureFragmentProgram(mSingleTextureFragmentProgram);
    }    / **
     * prepares的ProgramStore(控件使用的帧缓冲,如混合)
     * /
    私人无效initProgramStore(){
        mProgramStoreBlendNone = ProgramStore.BLEND_NONE_DEPTH_NONE(MRS);
        mScript.set_gProgramStoreBlendNone(mProgramStoreBlendNone);
    }    / **
     * prepares的ProgramVertex(顶点着色器)
     * /
    私人无效initProgramVertex(){
        ProgramVertexFixedFunction.Builder PVB =新ProgramVertexFixedFunction.Builder(MRS);
        mProgramVertex = pvb.create();
        ProgramVertexFixedFunction.Constants PVA =新ProgramVertexFixedFunction.Constants(MRS);
        ((ProgramVertexFixedFunction)mProgramVertex).bindConstants(PVA);
        Matrix4f PROJ =新Matrix4f();
        proj.loadProjectionNormalized(1,1);
        pva.setProjection(PROJ);
        mScript.set_gProgramVertex(mProgramVertex);
    }    / **
     * prepares采样器(控制像素如何从一个纹理拉)
     * /
    私人无效initSampler(){
        mLinearClamp = Sampler.CLAMP_LINEAR(MRS);
        mScript.set_gLinearClamp(mLinearClamp);
    }
}

RenderScript101View的内容

 包com.iangclifton.tutorials.renderscript;进口android.content.Context;
进口android.graphics.BitmapFactory;
进口android.renderscript.RSSurfaceView;
进口android.renderscript.RenderScriptGL;
进口android.view.MotionEvent;/ **
 *自定义RSSurfaceView,设置了RenderScript并捕捉触摸事件。
 *
 * @author伊恩·克利夫顿G.
 * /
公共类RenderScript101View扩展RSSurfaceView {
    私人语境mContext;
    私人RenderScript101RS mRenderScript;
    私人RenderScriptGL的mRS;    / **
     * {@inheritDoc}}
     * /
    公共RenderScript101View(上下文的背景下){
        超级(上下文);
        mContext =背景;
        ensureRenderScript();
    }    @覆盖
    公共布尔onTouchEvent(MotionEvent事件){
        super.onTouchEvent(事件);        如果(mRenderScript == NULL){
            返回true;
        }        如果(event.getAction()== MotionEvent.ACTION_DOWN){
            mRenderScript.setBackgroundBitmap(BitmapFactory.de codeResource(getResources(),R.drawable.icon00072half));
        }        返回true;
    }    / **
     *确保RenderScriptGL参照已经建立,我们的自定义
     * RS助手已创建。
     * /
    私人无效ensureRenderScript(){
        如果(MRS == NULL){
            最后RenderScriptGL.SurfaceConfig SC =新RenderScriptGL.SurfaceConfig();
            mRS评分= createRenderScriptGL(SC);
        }
        如果(mRenderScript == NULL){
            mRenderScript =新RenderScript101RS(MRS,mContext.getResources(),R.raw.renderscript101,R.raw.vdrender);
        }
    }
}


解决方案

有在你的LogCat中也不例外或警告,但我知道这个问题。

首先,我连看都不看你的RenderScript因为你说这正常工作对小位。

在Android的每个VM或进程有其自己的内存部分,这主要是不够的位图1920×1080。所以,你的logcat应该有提示这样的事情,你可能忽略了:

 位大小超过VM预算

我不知道你的实现细节(让位表格式的服务器,本地文件等)。因此,我将指导您 Android的位图培训

总的想法是,你需要加载图像小。受此:

  BitmapFactory.Options选项=新BitmapFactory.Options();
options.inJustDe codeBounds = TRUE;
BitmapFactory.de codeResource(getResources(),R.id.myimage,期权);
INT imageHeight = options.outHeight;
INT imageWidth = options.outWidth;
字符串IMAGETYPE = options.outMimeType;

关键部分:

  options.inJustDe codeBounds = TRUE;

说嘿!不要取消code和加载位图呢。我会做一些设置,以我的位图。

I am newbie to RenderScript and trying to process image with size 1920x1280px, this seems to be crashing every time with following error on logcat

09-04 19:26:04.670: D/dalvikvm(30308): GC_FOR_ALLOC freed 73K, 3% free 6615K/6787K, paused 26ms
09-04 19:26:04.680: I/dalvikvm-heap(30308): Grow heap (frag case) to 14.404MB for 8294416-byte allocation
09-04 19:26:04.690: D/dalvikvm(30308): GC_CONCURRENT freed 2K, 2% free 14713K/14919K, paused 1ms+1ms
09-04 19:26:04.820: D/dalvikvm(30308): GC_FOR_ALLOC freed 0K, 2% free 14713K/14919K, paused 12ms
09-04 19:26:04.820: I/dalvikvm-heap(30308): Grow heap (frag case) to 17.917MB for 3686416-byte allocation
09-04 19:26:04.840: D/dalvikvm(30308): GC_FOR_ALLOC freed 0K, 2% free 18313K/18567K, paused 13ms
09-04 19:26:04.860: D/dalvikvm(30308): GC_CONCURRENT freed 0K, 2% free 18313K/18567K, paused 1ms+2ms
09-04 19:26:05.010: A/libc(30308): Fatal signal 11 (SIGSEGV) at 0x5c41f809 (code=1)
09-04 19:26:05.010: A/libc(30308): Fatal signal 11 (SIGSEGV) at 0x5c41e001 (code=1)

where as the same code works if I resize the image to 100x56px :-(.

Please review the code below and suggest me any changes that needs to be done, the code is based on the example I found elsewhere on internet and from sample.

NOTE: The code below is not really production quality.

content of VDRender.rs

#pragma version(1)
#pragma rs java_package_name(com.iangclifton.tutorials.renderscript);

#include "rs_graphics.rsh"

const static float3 gMonoMult = {0.299f, 0.587f, 0.114f};

void root(const uchar4 *v_in, uchar4 *v_out) {

    //rsDebug("Called ROOT - ONE", rsUptimeMillis());

    float4 f4 = rsUnpackColor8888(*v_in);

    float3 mono = dot(f4.rgb, gMonoMult);
    *v_out = rsPackColorTo8888(mono);
}

content of RenderScript101.rs

#pragma version(1)
#pragma rs java_package_name(com.iangclifton.tutorials.renderscript);

#include "rs_graphics.rsh"

float4 gBgColor; // Background color as xyzw 4-part float
rs_allocation gBgImage; // Background image
rs_allocation gVDBgImage; // Background image

rs_sampler gLinearClamp; // Sampler used by the program fragment
rs_program_fragment gSingleTextureFragmentProgram; // fragment shader
rs_program_store gProgramStoreBlendNone; // blend none, depth none program store
rs_program_vertex gProgramVertex; // Default vertex shader

rs_script gVDScript;

static const float3 gBgVertices[4] = {
    { -1.0, -1.0, -1.0 },
    { 1.0, -1.0, -1.0 },
    { 1.0, 1.0, -1.0 },
    {-1.0, 1.0, -1.0 }
};

void drawInteger(int value, int x, int y) {

    char text[50] = "0";
    int index = 0;

    if(value != 0) {

    index = 49;
    text[index] = 0;

    while(value > 0) {

        index--;

        int digitValue = value % 10;

        text[index] = '0' + digitValue;

        value /= 10;
    }

    if(value < 0) {
        text[index--] = '-';
    }    
    }

    rsgDrawText(&text[index], x, y);
}

int64_t gTimeMS = 0;
int64_t updateFPS = 0;

int gFPS = 0;

static void drawBackground() {

    if (gBgImage.p != 0) {

        //rsgClearColor(gBgColor.x, gBgColor.y, gBgColor.z, gBgColor.w);

        rs_matrix4x4 projection, model;
        rsMatrixLoadOrtho(&projection, -1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f);
        rsgProgramVertexLoadProjectionMatrix(&projection);

        rsMatrixLoadIdentity(&model);
        rsgProgramVertexLoadModelMatrix(&model);

        // ----
        if(1) 
        {
            rsForEach(gVDScript, gBgImage, gBgImage, NULL);
            rsgBindTexture(gSingleTextureFragmentProgram, 0, gBgImage);
        }
        else
        {
            rsgBindTexture(gSingleTextureFragmentProgram, 0, gBgImage);
        }
        //----

        rsgDrawQuad(
            gBgVertices[0].x, gBgVertices[0].y, gBgVertices[0].z,
            gBgVertices[1].x, gBgVertices[1].y, gBgVertices[0].z,
            gBgVertices[2].x, gBgVertices[2].y, gBgVertices[0].z,
            gBgVertices[3].x, gBgVertices[3].y, gBgVertices[0].z
        );

        int x = 250;
        int y = 150;
        int fps = 0;

        int64_t t = rsUptimeMillis();
        int diff = t - gTimeMS;
        fps = 1000 / diff; 
        gTimeMS = t;

        if((t - updateFPS) > 500)
        {   
            gFPS = fps;
            updateFPS = t;
        }

        rsgDrawText("FPS:", x, y);
        drawInteger(gFPS, 250+40, 150);
    }
}

void init() {
    gBgColor = (float4) { 0.0f, 1.0f, 0.0f, 1.0f };
    rsDebug("Called init", rsUptimeMillis());
}

int root() {
    rsgBindProgramVertex(gProgramVertex);
    rsgBindProgramFragment(gSingleTextureFragmentProgram);
    rsgBindProgramStore(gProgramStoreBlendNone);

    drawBackground();
    return 1;
}

content of RenderScript101RS.java

package com.iangclifton.tutorials.renderscript;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.renderscript.Allocation;
import android.renderscript.Float4;
import android.renderscript.Matrix4f;
import android.renderscript.ProgramFragment;
import android.renderscript.ProgramFragmentFixedFunction;
import android.renderscript.ProgramStore;
import android.renderscript.ProgramVertex;
import android.renderscript.ProgramVertexFixedFunction;
import android.renderscript.RenderScriptGL;
import android.renderscript.Sampler;

/**
 * Custom RenderScript helper that simplifies interaction with the RenderScript.
 * 
 * @author Ian G. Clifton
 */
public class RenderScript101RS {

    private Sampler mLinearClamp;
    private ProgramStore mProgramStoreBlendNone;
    private ProgramVertex mProgramVertex;
    private RenderScriptGL mRS;
    private ScriptC_RenderScript101 mScript;
    private ScriptC_VDRender mVDScript;
    private ProgramFragment mSingleTextureFragmentProgram;

    /**
     * Constructs a new helper with RenderScriptGL and Resources references.
     * 
     * @param rs RenderScriptGL reference
     * @param res Resources reference
     * @param resId int ID of the RenderScript (e.g., R.raw.xyz)
     */
    public RenderScript101RS(RenderScriptGL rs, Resources res, int resId, int resId2) {
        mRS = rs;

        mScript = new ScriptC_RenderScript101(rs, res, resId);
        mVDScript = new ScriptC_VDRender(rs, res, resId2);

        mScript.set_gVDScript(mVDScript);

        initProgramStore();
        initSampler();
        initProgramFragment();
        initProgramVertex();
        mRS.bindRootScript(mScript);

    }

    /**
     * Sets a custom background Bitmap on the RenderScript view
     * 
     * @param bitmap Bitmap to use as the background
     */
    public void setBackgroundBitmap(Bitmap bitmap) {
        if (bitmap == null) {
            return;
        }
        final Allocation bitmapAllocation = Allocation.createFromBitmap(mRS, bitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_GRAPHICS_TEXTURE);
        mScript.set_gBgImage(bitmapAllocation);

        //final Allocation bitmapVDAllocation = Allocation.createFromBitmap(mRS, bitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_GRAPHICS_TEXTURE);
        //mScript.set_gVDBgImage(bitmapVDAllocation);
    }

    /**
     * Sets a custom background color on the RenderScript view
     * 
     * @param color Float4 color
     */
    public void setBackgroundColor(Float4 color) {
        mScript.set_gBgColor(color);
    }

    /**
     * Prepares the ProgramFragment (fragment shader)
     */
    private void initProgramFragment() {
        final ProgramFragmentFixedFunction.Builder pfBuilder = new ProgramFragmentFixedFunction.Builder(mRS);
        pfBuilder.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE, ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
        mSingleTextureFragmentProgram = pfBuilder.create();
        mScript.set_gSingleTextureFragmentProgram(mSingleTextureFragmentProgram);
    }

    /**
     * Prepares the ProgramStore (controls use of framebuffer such as blending)
     */
    private void initProgramStore() {
        mProgramStoreBlendNone = ProgramStore.BLEND_NONE_DEPTH_NONE(mRS);
        mScript.set_gProgramStoreBlendNone(mProgramStoreBlendNone);
    }

    /**
     * Prepares the ProgramVertex (vertex shader)
     */
    private void initProgramVertex() {
        ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS);
        mProgramVertex = pvb.create();
        ProgramVertexFixedFunction.Constants pva = new ProgramVertexFixedFunction.Constants(mRS);
        ((ProgramVertexFixedFunction) mProgramVertex).bindConstants(pva);
        Matrix4f proj = new Matrix4f();
        proj.loadProjectionNormalized(1, 1);
        pva.setProjection(proj);
        mScript.set_gProgramVertex(mProgramVertex);
    }

    /**
     * Prepares the Sampler (controls how pixels are pulled from a texture)
     */
    private void initSampler() {
        mLinearClamp = Sampler.CLAMP_LINEAR(mRS);
        mScript.set_gLinearClamp(mLinearClamp);
    }
}

content of RenderScript101View

package com.iangclifton.tutorials.renderscript;

import android.content.Context;
import android.graphics.BitmapFactory;
import android.renderscript.RSSurfaceView;
import android.renderscript.RenderScriptGL;
import android.view.MotionEvent;

/**
 * Custom RSSurfaceView that sets up the RenderScript and captures touch events.
 * 
 * @author Ian G. Clifton
 */
public class RenderScript101View extends RSSurfaceView {
    private Context mContext;
    private RenderScript101RS mRenderScript;
    private RenderScriptGL mRS;

    /**
     * {@inheritDoc}}
     */
    public RenderScript101View(Context context) {
        super(context);
        mContext = context;
        ensureRenderScript();
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        super.onTouchEvent(event);

        if (mRenderScript == null) {
            return true;
        }

        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            mRenderScript.setBackgroundBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.icon00072half));
        }

        return true;
    }

    /**
     * Ensures the RenderScriptGL reference has been established and our custom
     * RS helper has been created.
     */
    private void ensureRenderScript() {
        if (mRS == null) {
            final RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
            mRS = createRenderScriptGL(sc);
        }
        if (mRenderScript == null) {
            mRenderScript = new RenderScript101RS(mRS, mContext.getResources(), R.raw.renderscript101, R.raw.vdrender);
        }
    }
}

解决方案

There is no exception or warning in your LogCat but I may know the issue.

First off, I didn't even look at your RenderScript because you said it works fine for small bitmap.

In android each VM or process have its own portion of memory and this is mostly not enough for a bitmap 1920x1080. So your logcat should have prompt something like this that you may have neglected:

bitmap size exceeds VM budget

I don't know your implementation details (getting bitmap form server, local file etc.). So I will guide you to Android Bitmap Training.

The general idea is to load image as small as you need. By this:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(getResources(), R.id.myimage, options);
int imageHeight = options.outHeight;
int imageWidth = options.outWidth;
String imageType = options.outMimeType;

The crucial part:

options.inJustDecodeBounds = true;

Says hey! don't decode and load the bitmap yet. I will do some settings to my Bitmap.

这篇关于与Android加工1920x1280的图像 - RenderScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆