本文整理了Java中android.graphics.Bitmap.copy()
方法的一些代码示例,展示了Bitmap.copy()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bitmap.copy()
方法的具体详情如下:
包路径:android.graphics.Bitmap
类名称:Bitmap
方法名:copy
暂无
代码示例来源:origin: chentao0707/SimplifyReader
public static Bitmap doBlurJniArray(Bitmap sentBitmap, int radius, boolean canReuseInBitmap) {
Bitmap bitmap;
if (canReuseInBitmap) {
bitmap = sentBitmap;
} else {
bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
}
if (radius < 1) {
return (null);
}
int w = bitmap.getWidth();
int h = bitmap.getHeight();
int[] pix = new int[w * h];
bitmap.getPixels(pix, 0, w, 0, 0, w, h);
// Jni array calculate
ImageBlur.blurIntArray(pix, w, h, radius);
bitmap.setPixels(pix, 0, w, 0, 0, w, h);
return (bitmap);
}
代码示例来源:origin: stackoverflow.com
Bitmap base = source.copy(Config.ARGB_8888, true);
Bitmap blend = layer.copy(Config.ARGB_8888, false);
IntBuffer buffBase = IntBuffer.allocate(base.getWidth() * base.getHeight());
base.copyPixelsToBuffer(buffBase);
buffBase.rewind();
IntBuffer buffBlend = IntBuffer.allocate(blend.getWidth() * blend.getHeight());
blend.copyPixelsToBuffer(buffBlend);
buffBlend.rewind();
IntBuffer buffOut = IntBuffer.allocate(base.getWidth() * base.getHeight());
buffOut.rewind();
代码示例来源:origin: scola/Qart
public static Bitmap ProductEmbed(String txt, Bitmap input, boolean colorful, int color, int x, int y, Bitmap originBitmap){
int originalSize = input.getWidth();
Bitmap qrBitmap = Product(txt, input, colorful, color);
double newScale = 1.0 * originalSize * scaleQR / (qrBitmap.getWidth() - 2 * 4 * scaleQR);
int targetSize = qrBitmap.getWidth() * originalSize / (qrBitmap.getWidth() - 2 * 4 * scaleQR);
qrBitmap = resizeQuiteZone(qrBitmap, newScale); //it does not match QR spec to cut the qr quiet zone
qrBitmap = Bitmap.createScaledBitmap(qrBitmap, targetSize, targetSize, false);
originBitmap = originBitmap.copy(Bitmap.Config.ARGB_8888, true);
Canvas canvas = new Canvas(originBitmap);
canvas.drawBitmap(qrBitmap, x - (int) (4 * newScale), y - (int) (4 * newScale), null);
return originBitmap;
}
代码示例来源:origin: stackoverflow.com
// Setup to get a mutable bitmap less than 40 Kbytes
String path = "someSmallImage.jpg";
Bitmap bm0 = BitmapFactory.decodeFile(path);
// Need it mutable to change height
Bitmap bm1 = bm0.copy(bm0.getConfig(), true);
// Chop it to get a size less than 40K
bm1.setHeight(bm1.getHeight() / 32);
// Now we have a BitMap with size < 40K for the test
Bitmap bm2 = bm1.copy(bm0.getConfig(), true);
// What's the parcel size?
Parcel p1 = Parcel.obtain();
bm2.writeToParcel(p1, 0);
// Expect byteCount and allocatedByteCount to be the same
Log.i("Demo", String.format("byteCount=%d allocatedByteCount=%d parcelDataSize=%d",
bm2.getByteCount(), bm2.getAllocationByteCount(), p1.dataSize()));
// Resize to make byteCount and allocatedByteCount different
bm2.setHeight(bm2.getHeight() / 4);
// What's the parcel size?
Parcel p2 = Parcel.obtain();
bm2.writeToParcel(p2, 0);
// Show that byteCount determines size of data written to parcel
Log.i("Demo", String.format("byteCount=%d allocatedByteCount=%d parcelDataSize=%d",
bm2.getByteCount(), bm2.getAllocationByteCount(), p2.dataSize()));
p1.recycle();
p2.recycle();
代码示例来源:origin: TheFinestArtist/FinestWebView-Android
public static Bitmap getColoredBitmap(@NonNull Bitmap bitmap, @ColorInt int color) {
int alpha = Color.alpha(color);
int red = Color.red(color);
int green = Color.green(color);
int blue = Color.blue(color);
int[] pixels = new int[bitmap.getWidth() * bitmap.getHeight()];
bitmap.getPixels(pixels, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
for (int i = 0; i < pixels.length; i++) {
int pixel = pixels[i];
int pixelAlpha = Color.alpha(pixel);
if (pixelAlpha != 0) {
pixels[i] = Color.argb((int) (pixelAlpha * alpha / 256f), red, green, blue);
}
}
Bitmap coloredBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
coloredBitmap.setPixels(pixels, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(),
bitmap.getHeight());
return coloredBitmap;
}
代码示例来源:origin: stackoverflow.com
Bitmap base = source.copy(Config.ARGB_8888, true);
Bitmap blend = layer.copy(Config.ARGB_8888, false);
IntBuffer buffBase = IntBuffer.allocate(base.getWidth() * base.getHeight());
base.copyPixelsToBuffer(buffBase);
buffBase.rewind();
IntBuffer buffBlend = IntBuffer.allocate(blend.getWidth() * blend.getHeight());
blend.copyPixelsToBuffer(buffBlend);
buffBlend.rewind();
IntBuffer buffOut = IntBuffer.allocate(base.getWidth() * base.getHeight());
buffOut.rewind();
代码示例来源:origin: stackoverflow.com
SeekBar timerBar = (SeekBar) findViewById(R.id.seekBarTimer);
if (timerBar != null) {
timerBar.setMax((int) (Settings.countdownSeconds + 1));
timerBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar arg0) {
}
@Override
public void onStartTrackingTouch(SeekBar arg0) {
}
@Override
public void onProgressChanged(SeekBar timerBar, int arg1, boolean arg2) {
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.seek_thumb);
Bitmap bmp = bitmap.copy(Bitmap.Config.ARGB_8888, true);
Canvas c = new Canvas(bmp);
String text = Integer.toString(timerBar.getProgress());
Paint p = new Paint();
p.setTypeface(Typeface.DEFAULT_BOLD);
p.setTextSize(14);
p.setColor(0xFFFFFFFF);
int width = (int) p.measureText(text);
int yPos = (int) ((c.getHeight() / 2) - ((p.descent() + p.ascent()) / 2));
c.drawText(text, (bmp.getWidth()-width)/2, yPos, p);
timerBar.setThumb(new BitmapDrawable(getResources(), bmp));
}
});
timerBar.setProgress(0);
}
代码示例来源:origin: stackoverflow.com
Bitmap bitmap = b.copy(Bitmap.Config.ARGB_8888, true);
Bitmap sbmp;
if (bmp.getWidth() != radius || bmp.getHeight() != radius) {
float smallest = Math.min(bmp.getWidth(), bmp.getHeight());
float factor = smallest / radius;
sbmp = Bitmap.createScaledBitmap(bmp,
(int) (bmp.getWidth() / factor),
(int) (bmp.getHeight() / factor), false);
} else {
sbmp = bmp;
代码示例来源:origin: stackoverflow.com
Bitmap bitmap = BitmapFactory.decodeResource(
getResources(), com.cinchvalet.app.client.R.drawable.slider_pop_counter);
Bitmap bmp = bitmap.copy(Bitmap.Config.ARGB_8888, true);
Canvas c = new Canvas(bmp);
String text = "Your text";
Paint p = new Paint();
p.setTypeface(Typeface.DEFAULT_BOLD);
p.setTextSize(35);
p.setColor(getResources().getColor(com.cinchvalet.app.client.R.color.Black));
int width = (int) p.measureText(text);
int yPos = (int) ((c.getHeight() / 2)
- ((p.descent() + p.ascent()) / 2) - 10);
c.drawText(text, (bmp.getWidth() - width) / 2, yPos, p);
代码示例来源:origin: steelkiwi/cropiwa
public Bitmap applyCropTo(Bitmap bitmap) {
Bitmap immutableCropped = Bitmap.createBitmap(bitmap,
findRealCoordinate(bitmap.getWidth(), cropRect.left, imageRect.width()),
findRealCoordinate(bitmap.getHeight(), cropRect.top, imageRect.height()),
findRealCoordinate(bitmap.getWidth(), cropRect.width(), imageRect.width()),
findRealCoordinate(bitmap.getHeight(), cropRect.height(), imageRect.height()));
return immutableCropped.copy(immutableCropped.getConfig(), true);
}
代码示例来源:origin: luhaoaimama1/zone-sdk
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
paint.setColor(Color.RED);
paint.setStyle(Style.STROKE);
paint.setStrokeWidth(3);
paint.setTextSize(30);
Bitmap tmep = bt.copy(Config.ARGB_8888, true);
Canvas tmepCanvas = new Canvas(tmep);
tmepCanvas.drawCircle(0, 0, tmep.getWidth(), paint);
canvas.drawBitmap(tmep, 0, 200, paint);
paint.setStrokeWidth(0);
canvas.drawText("复制的原图是可以修改的", 0,400, paint);
canvas.drawBitmap(bt, 0, 0, paint);
canvas.drawText("原图", 0, 150, paint);
// 如果把原图 放到Canvas里去修改 那么会爆出这个错误
//AndroidRuntime(25875): java.lang.IllegalStateException: Immutable bitmap passed to Canvas constructor
// Canvas tmepCanvas2 = new Canvas(bt);
// tmepCanvas.drawCircle(0, 0, tmep.getWidth(), paint);
// canvas.drawBitmap(bt, 300, 0, paint);
// canvas.drawText("原图不能修改", 300, 150, paint);
}
代码示例来源:origin: stackoverflow.com
int width = Math.round(sentBitmap.getWidth() * scale);
int height = Math.round(sentBitmap.getHeight() * scale);
sentBitmap = Bitmap.createScaledBitmap(sentBitmap, width, height, false);
Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
int w = bitmap.getWidth();
int h = bitmap.getHeight();
代码示例来源:origin: stackoverflow.com
bitmap = bitmap.copy(bitmapConfig, true);
int x = (bitmap.getWidth() - bounds.width())/6;
int y = (bitmap.getHeight() + bounds.height())/5;
代码示例来源:origin: JessYanCoding/MVPArms
bitmap = sentBitmap;
} else {
bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
int w = bitmap.getWidth();
int h = bitmap.getHeight();
代码示例来源:origin: qiujuer/Genius-Android
Bitmap overlay = mBitmap.copy(mBitmap.getConfig(), true);
if (mCompress) {
radius = 3;
overlay = mCompressBitmap.copy(mCompressBitmap.getConfig(), true);
} else if (i == 2) {
int w = overlay.getWidth();
int h = overlay.getHeight();
int[] pix = new int[w * h];
overlay.getPixels(pix, 0, w, 0, 0, w, h);
代码示例来源:origin: wasabeef/glide-transformations
bitmap = sentBitmap;
} else {
bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
int w = bitmap.getWidth();
int h = bitmap.getHeight();
代码示例来源:origin: ArthurHub/Android-Image-Cropper
getRectFromPoints(
points,
bitmap.getWidth(),
bitmap.getHeight(),
fixAspectRatio,
aspectRatioX,
matrix.setRotate(degreesRotated, bitmap.getWidth() / 2, bitmap.getHeight() / 2);
matrix.postScale(flipHorizontally ? -scale : scale, flipVertically ? -scale : scale);
Bitmap result =
result = bitmap.copy(bitmap.getConfig(), false);
代码示例来源:origin: stackoverflow.com
Bitmap bitmap = src.copy(Bitmap.Config.ARGB_8888, true);
for(int x = 0;x < bitmap.getWidth();x++)
for(int y = 0;y < bitmap.getHeight();y++)
if(match(bitmap.getPixel(x, y)))
bitmap.setPixel(x, y, to);
代码示例来源:origin: wasabeef/Blurry
bitmap = sentBitmap;
} else {
bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
int w = bitmap.getWidth();
int h = bitmap.getHeight();
代码示例来源:origin: chentao0707/SimplifyReader
bitmap = sentBitmap;
} else {
bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
int w = bitmap.getWidth();
int h = bitmap.getHeight();
内容来源于网络,如有侵权,请联系作者删除!