本文整理了Java中android.widget.ImageView.setDrawingCacheEnabled()
方法的一些代码示例,展示了ImageView.setDrawingCacheEnabled()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ImageView.setDrawingCacheEnabled()
方法的具体详情如下:
包路径:android.widget.ImageView
类名称:ImageView
方法名:setDrawingCacheEnabled
暂无
代码示例来源:origin: fossasia/pslab-android
colorMap.setDrawingCacheEnabled(true);
Bitmap clickSpot = Bitmap.createBitmap(colorMap.getDrawingCache());
colorMap.setDrawingCacheEnabled(false);
try {
int pixel = clickSpot.getPixel((int) event.getX(), (int) event.getY());
代码示例来源:origin: stackoverflow.com
ImageView view;
...
ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
layoutParams.width = 400;
layoutParams.height = 400;
view.setLayoutParams(layoutParams);
Drawable drawable = view.getDrawable().mutate();//Vector
view.setImageDrawable(drawable);// <- that's a hack
view.setDrawingCacheEnabled(true);
Bitmap bitmap = container.getDrawingCache();
代码示例来源:origin: mylhyl/Android-Zxing
@Override
public void onClick(View v) {
imageView.setDrawingCacheEnabled(true);//step 1
Bitmap bitmap = imageView.getDrawingCache();//step 2
//step 3 转bytes
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
DeCodeActivity.gotoActivity(MainActivity.this, baos.toByteArray());//step 4
imageView.setDrawingCacheEnabled(false);//step 5
}
});
代码示例来源:origin: stackoverflow.com
ImageView imageView=(ImageView)findViewById(R.id.image);
imageView.setBackgroundResource(R.drawable.ic_launcher);
imageView.setDrawingCacheEnabled(true);
Drawable d=imageView.getBackground();
代码示例来源:origin: qyxxjd/BaseProject
/**
* 将ImageView转换为Bitmap.
*
* @param view 要转换为bitmap的View
* @return byte[] 图片的byte[]
*/
public static Bitmap imageView2Bitmap(@NonNull ImageView view) {
Bitmap bitmap = null;
try {
bitmap = Bitmap.createBitmap(view.getDrawingCache());
view.setDrawingCacheEnabled(false);
} catch (Exception e) {
e.printStackTrace();
}
return bitmap;
}
代码示例来源:origin: qyxxjd/AndroidBasicProject
/**
* 将ImageView转换为Bitmap.
*
* @param view 要转换为bitmap的View
* @return byte[] 图片的byte[]
*/
public static Bitmap imageView2Bitmap(ImageView view) {
Bitmap bitmap = null;
try {
bitmap = Bitmap.createBitmap(view.getDrawingCache());
view.setDrawingCacheEnabled(false);
} catch (Exception e) {
e.printStackTrace();
}
return bitmap;
}
代码示例来源:origin: microbit-foundation/microbit-blue
public int getHotspotColor (int hotspotId, int x, int y) {
ImageView img = (ImageView) findViewById(hotspotId);
img.setDrawingCacheEnabled(true);
Bitmap hotspots = Bitmap.createBitmap(img.getDrawingCache());
img.setDrawingCacheEnabled(false);
if (x >= 0 && y >= 0 && x <= hotspots.getWidth() && y <= hotspots.getHeight()) {
return hotspots.getPixel(x, y);
} else {
return 0;
}
}
代码示例来源:origin: zxfnicholas/CameraSDK
private void getViewBitmap() {
cropimage.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(cropimage.getDrawingCache());
// 清缓存
cropimage.destroyDrawingCache();
int w = cropimage.getWidth();
int h = cropimage.getHeight();
//itbmp = Bitmap.createBitmap(bitmap, 0, 0, 640, 640);
itbmp = Bitmap.createBitmap(bitmap, 0, 0, w, w);
bitmap=ThumbnailUtils.extractThumbnail(bitmap, 640, 640);// 缩放图片到指定的宽高到640px
}
代码示例来源:origin: stackoverflow.com
final ImageView tempImageView = new ImageView(getActivity());
final Bitmap tmp = BitmapFactory.decodeFile(LayoutParams.WRAP_CONTENT);
tempImageView.setImageBitmap(tmp);
tempImageView.setDrawingCacheEnabled(true);
// resize and create canvas
tempImageView.measure(MeasureSpec.makeMeasureSpec(256, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(256, MeasureSpec.EXACTLY));
tempImageView.layout(0, 0, tempImageView.getMeasuredWidth(), tempImageView.getMeasuredHeight());
tempImageView.buildDrawingCache(true);
final Bitmap resized_bm = Bitmap.createBitmap(tempImageView.getDrawingCache());
tempImageView.setDrawingCacheEnabled(false);
代码示例来源:origin: stackoverflow.com
ImageView img= new ImageView();
img=(ImageView) rrr.getChildAt(0);
img.setRotation(90);
img.setDrawingCacheEnabled(true);
img.buildDrawingCache();
if(img.isDrawingCacheEnabled()){
Bitmap bitmap =img.getDrawingCache(true);
}img.destroyDrawingCache();
img.setDrawingCacheEnabled(false);
ByteArrayOutputStream bao = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100,
bao);
int width = bitmap.getWidth();
int height = bitmap.getHeight();
Matrix matrix = new Matrix();
matrix.postRotate(90);
Bitmap rotatedBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
BitmapDrawable bmd = new BitmapDrawable(rotatedBitmap);
rrr.removeViewAt(0);
ImageView img_new=new ImageView(ImageSlideShow.this);
img_new.setImageDrawable(bmd);
img_new.setScaleType(ScaleType.CENTER);
rrr.addView(img_new, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
代码示例来源:origin: stackoverflow.com
mImageView = new WeakReference<>(imageView);
imageView.setDrawingCacheEnabled(true);
imageView.setOnTouchListener(this);
代码示例来源:origin: wsy858/android-headimage-cliper
/**
* 获取剪切图
*/
public Bitmap clip() {
imageView.setDrawingCacheEnabled(true);
imageView.buildDrawingCache();
Rect rect = clipView.getClipRect();
Bitmap cropBitmap = null;
Bitmap zoomedCropBitmap = null;
try {
cropBitmap = Bitmap.createBitmap(imageView.getDrawingCache(), rect.left, rect.top, rect.width(), rect.height());
zoomedCropBitmap = zoomBitmap(cropBitmap, 200, 200);
} catch (Exception e) {
e.printStackTrace();
}
if (cropBitmap != null) {
cropBitmap.recycle();
}
// 释放资源
imageView.destroyDrawingCache();
return zoomedCropBitmap;
}
代码示例来源:origin: SwiftyWang/FingerColoring-Android
public PhotoViewAttacher(ImageView imageView, boolean zoomable) {
mImageView = new WeakReference<>(imageView);
imageView.setDrawingCacheEnabled(true);
imageView.setOnTouchListener(this);
ViewTreeObserver observer = imageView.getViewTreeObserver();
if (null != observer)
observer.addOnGlobalLayoutListener(this);
// Make sure we using MATRIX Scale Type
setImageViewScaleTypeMatrix(imageView);
if (imageView.isInEditMode()) {
return;
}
// Create Gesture Detectors...
mScaleDragDetector = VersionedGestureDetector.newInstance(
imageView.getContext(), this);
mGestureDetector = new GestureDetector(imageView.getContext(),
new GestureDetector.SimpleOnGestureListener() {
// forward long click listener
@Override
public void onLongPress(MotionEvent e) {
if (null != mLongClickListener) {
mLongClickListener.onLongClick(getImageView());
}
}
});
//mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this));
// Finally, update the UI so that we're zoomable
setZoomable(zoomable);
}
代码示例来源:origin: tyhjh/JinyunEffect
private void setBackground() {
Bitmap bitmap = BlurUtil.doBlur(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_show), 10, 30);
iv_bg.setImageBitmap(bitmap);
iv_bg.setDrawingCacheEnabled(true);
getBitmap();
ColorMatrix colorMatrix = new ColorMatrix();
colorMatrix.setScale(0.7f, 0.7f, 0.7f, 1);
ColorMatrixColorFilter colorFilter = new ColorMatrixColorFilter(colorMatrix);
iv_bg.setColorFilter(colorFilter);
}
代码示例来源:origin: tyhjh/JinyunEffect
@Override
public void run() {
//启用DrawingCache并创建位图
iv_bg.buildDrawingCache();
while (iv_bg.getDrawingCache() == null) {
iv_bg.buildDrawingCache();
SystemClock.sleep(10);
}
Bitmap bitmap2 = Bitmap.createBitmap(iv_bg.getDrawingCache());
bitmap2 = Bitmap.createBitmap(bitmap2, 0, jinyunView.getTop(), jinyunView.getWidth(), jinyunView.getHeight());
jinyunView.setBitmapBg(bitmap2);
iv_bg.setDrawingCacheEnabled(false);
}
}).start();
代码示例来源:origin: JustinRoom/CameraMaskDemo
private void showCameraLensRectBitmap() {
ivBackground.setDrawingCacheEnabled(true);
Bitmap bitmap = ivBackground.getDrawingCache(true);
bitmap = cameraLensView.cropCameraLensRectBitmap(bitmap, false);
ImageView imageView = new ImageView(getContext());
imageView.setImageBitmap(bitmap);
BottomShowDialog dialog = new BottomShowDialog(getContext());
dialog.setTitle("ShowBitmapInCameraLensRect");
dialog.setBitmap(bitmap);
dialog.show();
}
}
代码示例来源:origin: MukeshKumar009/EcomSample
public PhotoViewAttacher(ImageView imageView, boolean zoomable) {
mImageView = new WeakReference<>(imageView);
imageView.setDrawingCacheEnabled(true);
imageView.setOnTouchListener(this);
ViewTreeObserver observer = imageView.getViewTreeObserver();
if (null != observer)
observer.addOnGlobalLayoutListener(this);
// Make sure we using MATRIX Scale Type
setImageViewScaleTypeMatrix(imageView);
if (imageView.isInEditMode()) {
return;
}
// Create Gesture Detectors...
mScaleDragDetector = VersionedGestureDetector.newInstance(
imageView.getContext(), this);
mGestureDetector = new GestureDetector(imageView.getContext(),
new GestureDetector.SimpleOnGestureListener() {
// forward long click listener
@Override
public void onLongPress(MotionEvent e) {
if (null != mLongClickListener) {
mLongClickListener.onLongClick(getImageView());
}
}
});
mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this));
// Finally, update the UI so that we're zoomable
setZoomable(zoomable);
}
代码示例来源:origin: SuperKotlin/PictureViewer
public PhotoViewAttacher(ImageView imageView) {
mImageView = new WeakReference<ImageView>(imageView);
imageView.setDrawingCacheEnabled(true);
imageView.setOnTouchListener(this);
ViewTreeObserver observer = imageView.getViewTreeObserver();
if (null != observer)
observer.addOnGlobalLayoutListener(this);
// Make sure we using MATRIX Scale Type
setImageViewScaleTypeMatrix(imageView);
if (imageView.isInEditMode()) {
return;
}
// Create Gesture Detectors...
mScaleDragDetector = VersionedGestureDetector.newInstance(
imageView.getContext(), this);
mGestureDetector = new GestureDetector(imageView.getContext(),
new GestureDetector.SimpleOnGestureListener() {
// forward long click listener
@Override
public void onLongPress(MotionEvent e) {
if (null != mLongClickListener) {
mLongClickListener.onLongClick(getImageView());
}
}
});
mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this));
// Finally, update the UI so that we're zoomable
setZoomable(true);
}
代码示例来源:origin: albinmathew/PhotoCrop
public PhotoViewAttacher(ImageView imageView) {
mImageView = new WeakReference<>(imageView);
imageView.setDrawingCacheEnabled(true);
imageView.setOnTouchListener(this);
代码示例来源:origin: xingkongus/superXingPostCard
private void init() {
ll = (LinearLayout) findViewById(R.id.ll);
ll.setDrawingCacheEnabled(true);
iv = (ImageView) findViewById(R.id.iv1);
iv.setDrawingCacheEnabled(true);
tv = (TextView) findViewById(R.id.tv1);
tv2 = (TextView) findViewById(R.id.tv_date);
getPhoto(iv);
}
内容来源于网络,如有侵权,请联系作者删除!