android高度设为0,错误:在更改对比度时,宽度和高度必须是> 0安卓_android_开发99编程知识库...

狄赞
2023-12-01

我的簡單圖像編輯器有問題。 經過對比更改后,我嘗試設置新的編輯圖像,但異常出現。public ContrastBrightnessDialog(Context context, String title, final DrawingView drawView) {

super(context);

this.setContentView(R.layout.contrastbrightness_dialog);

this.setTitle(title);

txtView = (TextView) findViewById(R.id.textView1);

contrastValue = (TextView) findViewById(R.id.contrast_value);

brightnessValue = (TextView) findViewById(R.id.textView1);

contrastSB = (SeekBar) findViewById(R.id.contrast_seekbar);

contrastSB.setProgress(0);

contrastSB.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

@Override

public void onProgressChanged(SeekBar seekBar,

int progress, boolean fromUser) {

//TODO Auto-generated method stub

contrastValue.setText(String.valueOf(progress - 100));

contrastInt = Integer.parseInt(String

. valueOf(progress - 100));

}

@Override

public void onStartTrackingTouch(SeekBar seekBar) {

//TODO Auto-generated method stub

}

@Override

public void onStopTrackingTouch(SeekBar seekBar) {

//TODO Auto-generated method stub

}

});

confirmBtn = (Button) findViewById(R.id.confirm_btn);

confirmBtn.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

drawView.setDrawingCacheEnabled(true);

drawView.measure(

MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),

MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));

drawView.layout(0, 0, drawView.getMeasuredWidth(),

drawView.getMeasuredHeight());

drawView.buildDrawingCache(true);

Bitmap bmin = Bitmap.createBitmap(drawView.getDrawingCache());

BitmapFactory.Options options = new BitmapFactory.Options();

options.inPreferredConfig = Bitmap.Config.ARGB_8888;

Bitmap workingBitmap = Bitmap.createBitmap(doContrast(bmin,

contrastInt));

Bitmap mutableBitmap = workingBitmap.copy(

Bitmap.Config.ARGB_8888, true);

options = new BitmapFactory.Options();

Drawable d = new BitmapDrawable(drawView.getResources(),

mutableBitmap);

drawView.setBackground(d);

drawView.setDrawingCacheEnabled(false);

close();

}

});

}

public Bitmap doContrast(Bitmap src, int value) {

//contrast algorithm from https://xjaphx.wordpress.com/2011/06/21/image-processing-contrast-image-on-the-fly/

return someBitmap;}

下面是我DrawingView類( 擴展 ImageView )的一個方法,它獲取和行出錯。 Debuger顯示w 和h 等於 0.@Override

protected void onSizeChanged(int w, int h, int oldw, int oldh) {

super.onSizeChanged(w, h, oldw, oldh);

canvasBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);//here is an error

drawCanvas = new Canvas(canvasBitmap);

}

 类似资料: