android 图库 imgcache.idx,Android : imgView.getDrawingCache() crops the Bitmap when I save in the stor...

I am adding a point on Canvas bitmap. Scale, Rotate and Move gestures are enabled on the ImageView. After that, I am saving the image in the external storage through a button click. But the bitmap is getting cropped (the size of bitmap is same as of my custom imageView). I am saving the point on canvas using imgView.getDrawingCache(). I don't want the saved bitmap to be cropped.

Save Function -

private void saveFunction() {

iv.setDrawingCacheEnabled(true);

Bitmap bitmap = iv.getDrawingCache(true);

/* BitmapDrawable drawable = (BitmapDrawable) iv.getDrawable();

Bitmap newBitmap = drawable.getBitmap();*/

String path =

Environment.getExternalStorageDirectory().getAbsolutePath();

File file = new File(path + File.separator + "name" + ".png");

Toast.makeText(getApplicationContext(), file.getAbsolutePath(),

Toast.LENGTH_LONG).show();

try {

if (!file.exists())

{

file.createNewFile();

}

FileOutputStream ostream = new FileOutputStream(file);

bitmap.compress(Bitmap.CompressFormat.PNG, 10, ostream);

ostream.close();

System.out.println("Rushi : saveFunction : saved");

} catch (Exception e) {

e.printStackTrace();

}

}

My custom ImageView class-

public class

DrawImageView extends ImageView {

private Paint currentPaint;

public boolean drawRect = false;

public float x;

public float y;

public Bitmap newBitmap;

public Matrix matrix;

public DrawImageView(Context context, @Nullable AttributeSet attrs) {

super(context, attrs);

currentPaint = new Paint();

currentPaint.setDither(true);

currentPaint.setColor(0xFF00CC00);

currentPaint.setStyle(Paint.Style.STROKE);

currentPaint.setStrokeJoin(Paint.Join.ROUND);

currentPaint.setStrokeCap(Paint.Cap.ROUND);

currentPaint.setStrokeWidth(60);

}

public void setNewBitmap(Bitmap bmp) {

newBitmap = bmp;

}

public Bitmap getNewBitmap() {

return newBitmap;

}

@Override

protected void onDraw(Canvas canvas) {

super.onDraw(canvas);

if (drawRect) {

canvas.drawPoint(x, y, currentPaint);

/* Matrix matrix = this.getImageMatrix();

float[] pts = {0, 0};

matrix.mapPoints(pts);

System.out.println("Rushi : NewPoint : "+pts[0]+","+pts[1]);*/

// canvas.drawBitmap(newBitmap, getImageMatrix(), null);

}

}

}

So basically, on clicking a button I am drawing a point, and then saving the image.

0c373515f359dff2aad92e38e99e9ebb.png

ab401199d9e4245367459e7dfb437785.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值