터치 이벤트에 응답하는보기에서 드로잉하기 위해 안드로이드의 API 샘플을 사용했습니다. 기본적으로 내가하는 일은 화면을 터치 할 때마다 내가 가지고있는 것 위에 원을 그립니다 (내용이 보존 된 것처럼 보이게하는 투명한 배경을 가진 원을 그립니다)비트 맵을 파일로 저장하여 검은 색 이미지로 표시
이제 문제는 이미지로 저장하려고 할 때. 나는 JPG와 PNG를 모두 시험해 보았고 나는 검은 색 그림을 얻는다. 어떻게 든 그것은 모든 투명한 재료를 검은 색으로 보이게 만듭니다.
이 비트 맵을 이미지 (선호하는 JPG)로 저장할 수있는 방법이 있습니까? 이미지 자체를 보면 투명도가 전혀 없습니다.
는
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
int curW = mBitmap != null ? mBitmap.getWidth() : 0;
int curH = mBitmap != null ? mBitmap.getHeight() : 0;
if (curW >= w && curH >= h) {
return;
}
if (curW < w) curW = w;
if (curH < h) curH = h;
Bitmap newBitmap = Bitmap.createBitmap(curW, curH, Bitmap.Config.ARGB_8888);
Canvas newCanvas = new Canvas();
newCanvas.setBitmap(newBitmap);
if (mBitmap != null) {
newCanvas.drawBitmap(mBitmap, 0, 0, null);
}
mBitmap = newBitmap;
mCanvas = newCanvas;
}
@Override
protected void onDraw(Canvas canvas) {
if (mBitmap != null) {
canvas.drawBitmap(mBitmap, 0, 0, null);
}
}
를 따를 때 나는 공공 다음과 같이 내가 저장
void paintmycolor(float x, float y, float major, float minor){
mPaint.setColor(myDrawColor);
mPaint.setAlpha(Math.min((int) (pressure * 128), 255));
canvas.save(Canvas.MATRIX_SAVE_FLAG);
RectF mReusableOvalRect = new RectF();
canvas.rotate((float) (orientation * 180/Math.PI), x, y);
mReusableOvalRect.left = x - minor/2;
mReusableOvalRect.right = x + minor/2;
mReusableOvalRect.top = y - major/2;
mReusableOvalRect.bottom = y + major/2;
canvas.drawOval(mReusableOvalRect, paint);
canvas.restore();
}
를 따를 때 내가보기 페인트 뷰를 초기화
을 요청한코드를 추가 주셔서 감사합니다 파일 saveBitmap() throws IOException {
File path=Environment.getExternalStoragePublicDirectory(android.os.Environment.DCIM);
File myDirectory = new File(path,mContext.getString(R.string.app_name));
if(!myDirectory.exists()){
myDirectory.mkdirs();
}
File output;
do {
int rand = new Random().nextInt();
output = new File(myDirectory,rand+".jpg");
}while(output.exists());
BufferedOutputStream ous = null;
try {
ous=new BufferedOutputStream(new FileOutputStream(output));
mBitmap.compress(CompressFormat.JPEG, 100, ous);
ous.flush();
ous.close();
return output;
} finally {
if (ous!=null) {
try {
ous.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.e("closing", e.getMessage());
}
}
}
}
당신이 당신의 원 사용자보기를 그리는 ... ?? 더 나은 이해는 몇 가지 코드를 보여 – koutuk
대한 그리기 원을 공유하시기 바랍니다. 몇 가지 문제점 : 1) JPG는 투명도를 지원하지 않으므로 검정색 배경이됩니다. 그리고 서클이 검은 색이면 잘 찾지 못할 것입니다. 2) SurfaceView를 사용하고 있습니까? 아니면 캔버스를 사용하고 있습니까? SurfaceView는 실제로 검정색 이미지를 캔버스에 그립니다. 캔버스를 사용하여 비트 맵을 캡처하면 SurfaceView 레이어가 아직 렌더링되지 않아서 비트 맵이 검정색이됩니다. –
관련성이있는 코드를 추가했습니다. 그것은 내가 확장하는 정상적인보기입니다 – Snake