2016-07-04 79 views
0

我使用此代碼繪製在Android

Uri selectedImage = data.getData(); 
String[] filePathColumn = { MediaStore.Images.Media.DATA }; 

Cursor cursor = getContentResolver().query(selectedImage, 
filePathColumn, null, null, null); 
cursor.moveToFirst(); 

int columnIndex = cursor.getColumnIndex(filePathColumn[0]); 
String picturePath = cursor.getString(columnIndex); 
cursor.close(); 

ImageView imageView = (ImageView) findViewById(R.id.imageView); 
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));` 

是工作,並顯示在imageview的知情同意加載PIC不是我要畫上一個圓圈,保存,我可以使用此代碼繪製

BitmapFactory.Options myOptions = new BitmapFactory.Options(); 
myOptions.inDither = true; 
myOptions.inScaled = false; 
myOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;// important 
myOptions.inPurgeable = true; 
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.ic_luncher); 
Paint paint = new Paint(); 
paint.setAntiAlias(true); 
paint.setColor(Color.BLUE); 

Bitmap workingBitmap = Bitmap.createBitmap(bitmap); 
Bitmap mutableBitmap = workingBitmap.copy(Bitmap.Config.ARGB_8888, true); 


Canvas canvas = new Canvas(mutableBitmap); 
canvas.drawCircle(60, 50, 25, paint); 

ImageView imageView = (ImageView)findViewById(R.id.imageView); 
imageView.setAdjustViewBounds(true); 
imageView.setImageBitmap(mutableBitmap);` 

但我不能畫,因爲它在位圖的資源上設置'ic_luncher'。 所以用戶不能畫上載圖片,我應該代替哪些代碼

Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.ic_luncher);

回答

0

不是使用Bitmap.copy,而是嘗試通過createBitmap創建一個相同大小的新位圖,然後將啓動器圖標繪製到這個新的位圖上。然後你可以在上面畫圖。