當前位置: 首頁>>代碼示例>>Java>>正文


Java Allocation.copyTo方法代碼示例

本文整理匯總了Java中android.renderscript.Allocation.copyTo方法的典型用法代碼示例。如果您正苦於以下問題:Java Allocation.copyTo方法的具體用法?Java Allocation.copyTo怎麽用?Java Allocation.copyTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.renderscript.Allocation的用法示例。


在下文中一共展示了Allocation.copyTo方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: blurMax

import android.renderscript.Allocation; //導入方法依賴的package包/類
public static Bitmap blurMax(Context context, Bitmap image) {
    // 計算圖片縮小後的長寬
    int width = Math.round(image.getWidth() * BITMAP_SCALE);
    int height = Math.round(image.getHeight() * BITMAP_SCALE);
    // 將縮小後的圖片做為預渲染的圖片。
    Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false);
    // 創建一張渲染後的輸出圖片。
    Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);
    // 創建RenderScript內核對象
    RenderScript rs = RenderScript.create(context);
    // 創建一個模糊效果的RenderScript的工具對象
    ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
    // 由於RenderScript並沒有使用VM來分配內存,所以需要使用Allocation類來創建和分配內存空間。
    // 創建Allocation對象的時候其實內存是空的,需要使用copyTo()將數據填充進去。
    Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
    Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
    // 設置渲染的模糊程度, 25f是最大模糊度
    blurScript.setRadius(25f);
    // 設置blurScript對象的輸入內存
    blurScript.setInput(tmpIn);
    // 將輸出數據保存到輸出內存中
    blurScript.forEach(tmpOut);
    // 將數據填充到Allocation中
    tmpOut.copyTo(outputBitmap);
    return outputBitmap;
}
 
開發者ID:funnyzhaov,項目名稱:Tribe,代碼行數:27,代碼來源:BlurBitmap.java

示例2: blur

import android.renderscript.Allocation; //導入方法依賴的package包/類
public static Bitmap blur(Context context, Bitmap image) {
    int width = Math.round(image.getWidth() * BITMAP_SCALE);
    int height = Math.round(image.getHeight() * BITMAP_SCALE);

    Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false);
    Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);

    RenderScript rs = RenderScript.create(context);
    ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
    Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
    Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
    theIntrinsic.setRadius(BLUR_RADIUS);
    theIntrinsic.setInput(tmpIn);
    theIntrinsic.forEach(tmpOut);
    tmpOut.copyTo(outputBitmap);

    return outputBitmap;
}
 
開發者ID:alepacheco,項目名稱:AndroRW,代碼行數:19,代碼來源:BlurBuilder.java

示例3: blurBitmap

import android.renderscript.Allocation; //導入方法依賴的package包/類
public static Bitmap blurBitmap(Context context, Bitmap bmp, float radius) {
    Bitmap out = Bitmap.createBitmap(bmp);
    RenderScript rs = RenderScript.create(context);
    radius = Math.min(Math.max(radius, 0), 25);

    Allocation input = Allocation.createFromBitmap(
            rs, bmp, MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
    Allocation output = Allocation.createTyped(rs, input.getType());

    ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
    script.setInput(input);
    script.setRadius(radius);
    script.forEach(output);

    output.copyTo(out);

    rs.destroy();
    return out;
}
 
開發者ID:WrBug,項目名稱:GravityBox,代碼行數:20,代碼來源:Utils.java

示例4: blur

import android.renderscript.Allocation; //導入方法依賴的package包/類
public Bitmap blur(Context context, Bitmap image) {
    int width = Math.round(image.getWidth() * BITMAP_SCALE);
    int height = Math.round(image.getHeight() * BITMAP_SCALE);

    Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false);
    Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);

    RenderScript rs = RenderScript.create(context);
    ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
    Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
    Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
    theIntrinsic.setRadius(BLUR_RADIUS);
    theIntrinsic.setInput(tmpIn);
    theIntrinsic.forEach(tmpOut);
    tmpOut.copyTo(outputBitmap);

    return outputBitmap;
}
 
開發者ID:ApplikeySolutions,項目名稱:OrionPreview,代碼行數:19,代碼來源:BlurAnimation.java

示例5: renderScriptBlur

import android.renderscript.Allocation; //導入方法依賴的package包/類
/**
 * renderScript模糊圖片
 * <p>API大於17</p>
 *
 * @param src     源圖片
 * @param radius  模糊半徑(0...25)
 * @param recycle 是否回收
 * @return 模糊後的圖片
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static Bitmap renderScriptBlur(final Bitmap src, final float radius, final boolean recycle) {
	if (isEmptyBitmap(src)) {
		return null;
	}
	RenderScript rs = null;
	Bitmap ret = recycle ? src : src.copy(src.getConfig(), true);
	try {
		rs = RenderScript.create(Utils.getApp());
		rs.setMessageHandler(new RenderScript.RSMessageHandler());
		Allocation input = Allocation.createFromBitmap(rs, ret, Allocation.MipmapControl.MIPMAP_NONE, Allocation
				.USAGE_SCRIPT);
		Allocation output = Allocation.createTyped(rs, input.getType());
		ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
		blurScript.setInput(input);
		blurScript.setRadius(radius);
		blurScript.forEach(output);
		output.copyTo(ret);
	} finally {
		if (rs != null) {
			rs.destroy();
		}
	}
	return ret;
}
 
開發者ID:MobClub,項目名稱:BBSSDK-for-Android,代碼行數:35,代碼來源:ImageUtils.java

示例6: blur

import android.renderscript.Allocation; //導入方法依賴的package包/類
public Bitmap blur(Bitmap image) {
    if (null == image) return null;

    Bitmap outputBitmap = Bitmap.createBitmap(image);
    final RenderScript renderScript = RenderScript.create(this);
    Allocation tmpIn = Allocation.createFromBitmap(renderScript, image);
    Allocation tmpOut = Allocation.createFromBitmap(renderScript, outputBitmap);

    //Intrinsic Gausian blur filter
    ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));
    theIntrinsic.setRadius(BLUR_RADIUS);
    theIntrinsic.setInput(tmpIn);
    theIntrinsic.forEach(tmpOut);
    tmpOut.copyTo(outputBitmap);
    return outputBitmap;
}
 
開發者ID:mdnafiskhan,項目名稱:Mp3Player,代碼行數:17,代碼來源:MusicPlayerActivity.java

示例7: rsBlur

import android.renderscript.Allocation; //導入方法依賴的package包/類
public static Bitmap rsBlur(Context context, Bitmap source, int radius) {

        // 計算圖片縮小後的長寬
        int width = Math.round(source.getWidth() * BITMAP_SCALE);
        int height = Math.round(source.getHeight() * BITMAP_SCALE);

        // 將縮小後的圖片做為預渲染的圖片
        Bitmap inputBitmap = Bitmap.createScaledBitmap(source, width, height, false);

        RenderScript renderScript = RenderScript.create(context);
        final Allocation input = Allocation.createFromBitmap(renderScript, inputBitmap);
        final Allocation outPut = Allocation.createTyped(renderScript, input.getType());

        ScriptIntrinsicBlur scriptIntrinsicBlur = ScriptIntrinsicBlur.create(renderScript,
                Element.U8_4(renderScript));
        scriptIntrinsicBlur.setInput(input);
        scriptIntrinsicBlur.setRadius(radius);
        scriptIntrinsicBlur.forEach(outPut);
        outPut.copyTo(inputBitmap);
        renderScript.destroy();

        return inputBitmap;
    }
 
開發者ID:yinyiliang,項目名稱:RabbitCloud,代碼行數:24,代碼來源:RenderScriptHelper.java

示例8: blurBitmap

import android.renderscript.Allocation; //導入方法依賴的package包/類
/**
 * 圖片高斯模糊
 *
 * @param context
 * @param bitmap
 * @return
 */
public static Bitmap blurBitmap(Context context, Bitmap bitmap) {
    //用需要創建高斯模糊bitmap創建一個空的bitmap
    Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    // 初始化Renderscript,該類提供了RenderScript context,創建其他RS類之前必須先創建這個類,其控製RenderScript的初始化,資源管理及釋放
    RenderScript rs = RenderScript.create(context);
    // 創建高斯模糊對象
    ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
    // 創建Allocations,此類是將數據傳遞給RenderScript內核的主要方 法,並製定一個後備類型存儲給定類型
    Allocation allIn = Allocation.createFromBitmap(rs, bitmap);
    Allocation allOut = Allocation.createFromBitmap(rs, outBitmap);
    //設定模糊度(注:Radius最大隻能設置25.f)
    blurScript.setRadius(15f);
    // Perform the Renderscript
    blurScript.setInput(allIn);
    blurScript.forEach(allOut);
    allOut.copyTo(outBitmap);
    rs.destroy();
    return outBitmap;
}
 
開發者ID:NICOLITE,項目名稱:HutHelper,代碼行數:27,代碼來源:CommUtil.java

示例9: renderScriptBlur

import android.renderscript.Allocation; //導入方法依賴的package包/類
/**
 * renderScript模糊圖片
 * <p>API大於17</p>
 *
 * @param context 上下文
 * @param src 源圖片
 * @param radius 模糊半徑(0...25)
 * @return 模糊後的圖片
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static Bitmap renderScriptBlur(Context context, Bitmap src, @FloatRange(from = 0, to = 25, fromInclusive = false) float radius) {
    if (isEmptyBitmap(src)) {
        return null;
    }
    RenderScript rs = null;
    try {
        rs = RenderScript.create(context);
        rs.setMessageHandler(new RenderScript.RSMessageHandler());
        Allocation input = Allocation
                .createFromBitmap(rs, src, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
        Allocation output = Allocation.createTyped(rs, input.getType());
        ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur
                .create(rs, Element.U8_4(rs));
        blurScript.setInput(input);
        blurScript.setRadius(radius);
        blurScript.forEach(output);
        output.copyTo(src);
    } finally {
        if (rs != null) {
            rs.destroy();
        }
    }
    return src;
}
 
開發者ID:imliujun,項目名稱:LJFramework,代碼行數:35,代碼來源:ImageUtils.java

示例10: blurBitmap

import android.renderscript.Allocation; //導入方法依賴的package包/類
public static Bitmap blurBitmap(Context context, Bitmap bitmap) {
    if (context == null || bitmap == null) return null;

    Bitmap blurredBitmap;
    try {
        blurredBitmap = Bitmap.createBitmap(bitmap);
    } catch (OutOfMemoryError e) {
        return null;
    }

    RenderScript renderScript = RenderScript.create(context);
    Allocation input = Allocation.createFromBitmap(renderScript, bitmap, Allocation.MipmapControl.MIPMAP_FULL, Allocation.USAGE_SCRIPT);
    Allocation output = Allocation.createTyped(renderScript, input.getType());
    ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));

    script.setInput(input);
    script.setRadius(20);

    script.forEach(output);
    output.copyTo(blurredBitmap);

    return blurredBitmap;
}
 
開發者ID:TheAndroidMaster,項目名稱:Rocket,代碼行數:24,代碼來源:ImageUtils.java

示例11: blur

import android.renderscript.Allocation; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static Bitmap blur(Context context, Bitmap image) {
    int width = Math.round(image.getWidth() * BITMAP_SCALE);
    int height = Math.round(image.getHeight() * BITMAP_SCALE);

    Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false);
    Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);

    RenderScript rs = RenderScript.create(context);
    ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
    Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
    Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
    theIntrinsic.setRadius(BLUR_RADIUS);
    theIntrinsic.setInput(tmpIn);
    theIntrinsic.forEach(tmpOut);
    tmpOut.copyTo(outputBitmap);

    return outputBitmap;
}
 
開發者ID:HCMUS-AssignmentWarehouse,項目名稱:FastFoodFinder,代碼行數:20,代碼來源:DisplayUtils.java

示例12: transform

import android.renderscript.Allocation; //導入方法依賴的package包/類
@Override
public Bitmap transform(Bitmap bitmap) {
    // Create another bitmap that will hold the results of the filter.
    Bitmap blurredBitmap = Bitmap.createBitmap(bitmap);

    // Allocate memory for Renderscript to work with
    Allocation input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_FULL, Allocation.USAGE_SHARED);
    Allocation output = Allocation.createTyped(rs, input.getType());

    // Load up an instance of the specific script that we want to use.
    ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
    script.setInput(input);

    // Set the blur radius
    script.setRadius(25);

    // Start the ScriptIntrinisicBlur
    script.forEach(output);

    // Copy the output to the blurred bitmap
    output.copyTo(blurredBitmap);

    return blurredBitmap;
}
 
開發者ID:salRoid,項目名稱:Clasick,代碼行數:25,代碼來源:BlurTransform.java

示例13: blurRenderScript

import android.renderscript.Allocation; //導入方法依賴的package包/類
private Bitmap blurRenderScript(Bitmap smallBitmap, int radius) {

        int width  = Math.round(smallBitmap.getWidth() * defaultBitmapScale);
        int height = Math.round(smallBitmap.getHeight() * defaultBitmapScale);

        Bitmap inputBitmap  = Bitmap.createScaledBitmap(smallBitmap, width, height, false);
        Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);

        RenderScript renderScript = RenderScript.create(getContext());
        ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));
        Allocation tmpIn = Allocation.createFromBitmap(renderScript, inputBitmap);
        Allocation tmpOut = Allocation.createFromBitmap(renderScript, outputBitmap);
        theIntrinsic.setRadius(radius);
        theIntrinsic.setInput(tmpIn);
        theIntrinsic.forEach(tmpOut);
        tmpOut.copyTo(outputBitmap);

        return outputBitmap;
    }
 
開發者ID:jgabrielfreitas,項目名稱:BlurImageView,代碼行數:20,代碼來源:BlurImageView.java

示例14: blur

import android.renderscript.Allocation; //導入方法依賴的package包/類
@TargetApi(17)
public static Bitmap blur(Context context, Bitmap image) {
    int width = Math.round(image.getWidth() * BITMAP_SCALE);
    int height = Math.round(image.getHeight() * BITMAP_SCALE);

    Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false);
    Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);

    RenderScript rs = RenderScript.create(context);
    ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
    Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
    Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
    theIntrinsic.setRadius(BLUR_RADIUS);
    theIntrinsic.setInput(tmpIn);
    theIntrinsic.forEach(tmpOut);
    tmpOut.copyTo(outputBitmap);

    return outputBitmap;
}
 
開發者ID:jtran064,項目名稱:PlatePicks-Android,代碼行數:20,代碼來源:BlurImageTool.java

示例15: blur

import android.renderscript.Allocation; //導入方法依賴的package包/類
/**
 * 使用RenderScript實現高斯模糊的算法
 * @param bitmap
 * @return
 */
public Bitmap blur(Bitmap bitmap){
    //Let's create an empty bitmap with the same size of the bitmap we want to blur
    Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    //Instantiate a new Renderscript
    RenderScript rs = RenderScript.create(getApplicationContext());
    //Create an Intrinsic Blur Script using the Renderscript
    ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
    //Create the Allocations (in/out) with the Renderscript and the in/out bitmaps
    Allocation allIn = Allocation.createFromBitmap(rs, bitmap);
    Allocation allOut = Allocation.createFromBitmap(rs, outBitmap);
    //Set the radius of the blur: 0 < radius <= 25
    blurScript.setRadius(20.0f);
    //Perform the Renderscript
    blurScript.setInput(allIn);
    blurScript.forEach(allOut);
    //Copy the final bitmap created by the out Allocation to the outBitmap
    allOut.copyTo(outBitmap);
    //recycle the original bitmap
    bitmap.recycle();
    //After finishing everything, we destroy the Renderscript.
    rs.destroy();

    return outBitmap;

}
 
開發者ID:imageprocessor,項目名稱:cv4j,代碼行數:31,代碼來源:GaussianBlurActivity.java


注:本文中的android.renderscript.Allocation.copyTo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。