本文整理匯總了Java中android.support.v8.renderscript.Allocation.createFromBitmap方法的典型用法代碼示例。如果您正苦於以下問題:Java Allocation.createFromBitmap方法的具體用法?Java Allocation.createFromBitmap怎麽用?Java Allocation.createFromBitmap使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v8.renderscript.Allocation
的用法示例。
在下文中一共展示了Allocation.createFromBitmap方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doInBackground
import android.support.v8.renderscript.Allocation; //導入方法依賴的package包/類
@Override
protected Drawable doInBackground(Drawable... drawables) {
finalResult = ArtworkUtils.optimizeBitmap(bitmap, bitmap.getWidth());
if (finalResult != null && finalResult.getConfig() != null) {
scriptIntrinsicBlur = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));
allocationIn = Allocation.createFromBitmap(renderScript, finalResult, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT | Allocation.USAGE_SHARED);
allocationOut = Allocation.createTyped(renderScript, allocationIn.getType());
scriptIntrinsicBlur.setRadius(radius); //radius option from users
scriptIntrinsicBlur.setInput(allocationIn);
scriptIntrinsicBlur.forEach(allocationOut);
allocationOut.copyTo(finalResult);
bitmapDrawable = new BitmapDrawable(context.getResources(), finalResult);
return bitmapDrawable;
} else {
Drawable defaultDrawable = ContextCompat.getDrawable(context, R.mipmap.ic_launcher);
return defaultDrawable;
}
}
示例2: getExpectedHistogram
import android.support.v8.renderscript.Allocation; //導入方法依賴的package包/類
@NonNull
private int[] getExpectedHistogram(RenderScript rs, Bitmap bmpFromNv21, Op op) {
Allocation ain = Allocation.createFromBitmap(rs, bmpFromNv21);
Allocation aout;
int[] histogram;
if (op == Op.LUMINANCE) {
aout = Allocation.createSized(rs, Element.I32(rs), Histogram.COLOR_DEPTH);
histogram = new int[Histogram.COLOR_DEPTH];
}
else {
aout = Allocation.createSized(rs, Element.I32_4(rs), Histogram.COLOR_DEPTH);
histogram = new int[Histogram.COLOR_DEPTH * Histogram.CHANNELS];
}
ScriptIntrinsicHistogram histogramScript = ScriptIntrinsicHistogram.create(
rs, ain.getElement());
histogramScript.setOutput(aout);
histogramScript.forEach(ain);
aout.copyTo(histogram);
return histogram;
}
示例3: blur
import android.support.v8.renderscript.Allocation; //導入方法依賴的package包/類
public void blur(Bitmap originBitmap) {
Bitmap scaledBitmap = Bitmap.createScaledBitmap(originBitmap, originBitmap.getWidth() / scaleRatio, originBitmap.getHeight() / scaleRatio, false);
Bitmap mBitmapToBlur = scaledBitmap.copy(Bitmap.Config.ARGB_8888, true);
Bitmap mBlurredBitmap = Bitmap.createBitmap(mBitmapToBlur.getWidth(), mBitmapToBlur.getHeight(),
Bitmap.Config.ARGB_8888);
mRenderScript = RenderScript.create(getContext());
mBlurScript = ScriptIntrinsicBlur.create(mRenderScript, Element.U8_4(mRenderScript));
mBlurInput = Allocation.createFromBitmap(mRenderScript, mBitmapToBlur,
Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
mBlurOutput = Allocation.createTyped(mRenderScript, mBlurInput.getType());
mBlurInput.copyFrom(mBitmapToBlur);
mBlurScript.setRadius(blurRadius);
mBlurScript.setInput(mBlurInput);
mBlurScript.forEach(mBlurOutput);
mBlurOutput.copyTo(mBlurredBitmap);
drawableFadeDisplayer.display(mBlurredBitmap, this);
scaledBitmap.recycle();
mBitmapToBlur.recycle();
mRenderScript.destroy();
}
示例4: blur
import android.support.v8.renderscript.Allocation; //導入方法依賴的package包/類
/**
* @param bitmap bitmap to blur
* @param blurRadius blur radius (1..25)
* @return blurred bitmap
*/
@Override
public final Bitmap blur(Bitmap bitmap, float blurRadius) {
//Allocation will use the same backing array of pixels as bitmap if created with USAGE_SHARED flag
Allocation inAllocation = Allocation.createFromBitmap(renderScript, bitmap);
if (!canReuseAllocation(bitmap)) {
if (outAllocation != null) {
outAllocation.destroy();
}
outAllocation = Allocation.createTyped(renderScript, inAllocation.getType());
lastBitmapWidth = bitmap.getWidth();
lastBitmapHeight = bitmap.getHeight();
}
blurScript.setRadius(blurRadius);
blurScript.setInput(inAllocation);
//do not use inAllocation in forEach. it will cause visual artifacts on blurred Bitmap
blurScript.forEach(outAllocation);
outAllocation.copyTo(bitmap);
inAllocation.destroy();
return bitmap;
}
示例5: blur
import android.support.v8.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;
}
示例6: transform
import android.support.v8.renderscript.Allocation; //導入方法依賴的package包/類
@Override
public Bitmap transform(Bitmap source) {
try {
final RenderScript rs = RenderScript.create(context);
final Allocation input = Allocation.createFromBitmap(rs, source, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
final Allocation output = Allocation.createTyped(rs, input.getType());
final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
script.setRadius(14.f);
script.setInput(input);
script.forEach(output);
output.copyTo(source);
} catch (Exception e) {
e.printStackTrace();
}
return source;
}
示例7: blur
import android.support.v8.renderscript.Allocation; //導入方法依賴的package包/類
@Override
protected Bitmap blur(Context context, Bitmap bitmapToBlur, int radius) {
Log.i(TAG, "Current build version sdk " + Build.VERSION.SDK_INT);
Bitmap bitmap = bitmapToBlur.copy(bitmapToBlur.getConfig(), true);
final RenderScript renderScript = RenderScript.create(context, Build.VERSION.SDK_INT);
final Allocation input = Allocation.createFromBitmap(renderScript, bitmapToBlur,
Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
final Allocation output = Allocation.createTyped(renderScript, input.getType());
try {
final ScriptIntrinsicBlur script = createBlurringScript(radius, renderScript, input);
script.forEach(output);
renderScript.finish();
output.copyTo(bitmap);
} finally {
input.destroy();
output.destroy();
bitmapToBlur.recycle();
renderScript.destroy();
}
return bitmap;
}
示例8: blurImageWithRs
import android.support.v8.renderscript.Allocation; //導入方法依賴的package包/類
public static Bitmap blurImageWithRs(Context context, Bitmap input, int radius) {
RenderScript renderScript = RenderScript.create(context);
Allocation allocation = Allocation.createFromBitmap(renderScript, input);
ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));
blur.setRadius(radius);
blur.setInput(allocation);
Bitmap result = Bitmap.createBitmap(input.getWidth(), input.getHeight(), input.getConfig());
Allocation outAlloc = Allocation.createFromBitmap(renderScript, result);
blur.forEach(outAlloc);
outAlloc.copyTo(result);
renderScript.destroy();
return result;
}
示例9: renderScriptBlur
import android.support.v8.renderscript.Allocation; //導入方法依賴的package包/類
/**
* Blurs a bitmap using RenderScript (source : http://trickyandroid.com/advanced-blurring-techniques/,
* https://plus.google.com/+MarioViviani/posts/fhuzYkji9zz)
* @param originalBitmap Original bitmap to be blurred (not altered)
* @param radius Blur amount
* @return Blurred bitmap
*/
public static Bitmap renderScriptBlur(Bitmap originalBitmap, float radius) {
Bitmap outBitmap = Bitmap.createBitmap(originalBitmap.getWidth(), originalBitmap.getHeight(),
Bitmap.Config.ARGB_8888);
RenderScript rs = Foofy.getInstance().getRenderScriptContext();
ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
Allocation allIn = Allocation.createFromBitmap(rs, originalBitmap);
Allocation allOut = Allocation.createFromBitmap(rs, outBitmap);
blurScript.setRadius(radius > 25 ? 25 : radius);
blurScript.setInput(allIn);
blurScript.forEach(allOut);
allOut.copyTo(outBitmap);
//rs.destroy();
if (radius > 25)
return renderScriptBlur(outBitmap, radius-25);
else
return outBitmap;
}
示例10: alloc
import android.support.v8.renderscript.Allocation; //導入方法依賴的package包/類
private void alloc(Bitmap inBmp, Bitmap outBmp) {
if (mInAllocation != null) {
mInAllocation.destroy();
mInAllocation = null;
}
if (inBmp != null) {
mInAllocation = Allocation.createFromBitmap(mRS, inBmp);
}
if (mOutAllocation != null) {
mOutAllocation.destroy();
mOutAllocation = null;
}
if (outBmp != null) {
mOutAllocation = Allocation.createFromBitmap(mRS, outBmp);
}
}
示例11: transform
import android.support.v8.renderscript.Allocation; //導入方法依賴的package包/類
@Override
protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
Bitmap blurredBitmap = toTransform.copy(Bitmap.Config.ARGB_8888, true);
// Allocate memory for Renderscript to work with
Allocation input = Allocation.createFromBitmap(rs, blurredBitmap, 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(10);
// Start the ScriptIntrinisicBlur
script.forEach(output);
// Copy the output to the blurred bitmap
output.copyTo(blurredBitmap);
toTransform.recycle();
return blurredBitmap;
}
示例12: apply
import android.support.v8.renderscript.Allocation; //導入方法依賴的package包/類
public static Bitmap apply(Context context, Bitmap sentBitmap, int radius) {
final Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
final RenderScript rs = RenderScript.create(context);
final Allocation input = Allocation.createFromBitmap(rs, sentBitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
final Allocation output = Allocation.createTyped(rs, input.getType());
final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
script.setRadius(radius);
script.setInput(input);
script.forEach(output);
output.copyTo(bitmap);
sentBitmap.recycle();
rs.destroy();
input.destroy();
output.destroy();
script.destroy();
return bitmap;
}
示例13: allocateBitmap
import android.support.v8.renderscript.Allocation; //導入方法依賴的package包/類
private Data allocateBitmap(int scaled_width, int scaled_height) {
// calculate scaled width/height
if (scaled_width > 0 && scaled_height > 0) {
Point size = new Point(scaled_width, scaled_height);
// check cache
Data data = mCache.get(size);
if (data != null) {
// found cached data, use it.
return data;
} else {
// create the new
data = new Data();
data.bitmap = Bitmap.createBitmap(scaled_width, scaled_height, Bitmap.Config.ARGB_8888);
if (mRenderScript != null) {
data.allocation = Allocation.createFromBitmap(mRenderScript, data.bitmap);
data.filter = ScriptIntrinsicBlur.create(mRenderScript, data.allocation.getElement());
}
// save to cache
mCache.put(size, data);
return data;
}
}
return null;
}
示例14: blurBitmap
import android.support.v8.renderscript.Allocation; //導入方法依賴的package包/類
/**
* https://plus.google.com/+MarioViviani/posts/fhuzYkji9zz
*
* @param context
* @param bitmap
* @return
*/
public static Bitmap blurBitmap(Context context, 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(context);
//Create an Intrinsic Blur Script using the Renderscript
ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
//Create the in/out Allocations 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
blurScript.setRadius(25.f);
//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;
}
示例15: blur
import android.support.v8.renderscript.Allocation; //導入方法依賴的package包/類
public Bitmap blur(Bitmap image) {
if (image == null)
return null;
image = RGB565toARGB888(image);
if (!configured) {
input = Allocation.createFromBitmap(rs, image);
output = Allocation.createTyped(rs, input.getType());
script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
script.setRadius(BLUR_RADIUS);
configured = true;
} else
input.copyFrom(image);
script.setInput(input);
script.forEach(output);
output.copyTo(image);
return image;
}