gpt4 book ai didi

android - 使用 Canvas 和 canvas.scale(Scale, Scale) 的图像质量问题;

转载 作者:行者123 更新时间:2023-11-29 18:14:21 26 4
gpt4 key购买 nike

我在使用 Canvas 和 canvas.scale(Scale, Scale) 时遇到图像质量问题;它们看起来完全像下面这样:

android:运行时调整大小的图像质量

我相信我已经阅读了所有关于调整位图大小时图像质量问题的帖子,但是当使用 Canvas 缩放(浮点缩放)缩放时它似乎没有帮助。

我已经按照图像质量帖子的建议尝试了许多不同的选项。

BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = false;
options.inDither = false;
options.inSampleSize = 1;
options.inScaled = false;
options.inPreferredConfig = Bitmap.Config.ARGB_8888;//I thought this would do it
CurrentPicture = BitmapFactory.decodeFile(path, options);//Also tried decodeStream()


PicturePaint = new Paint();
//PicturePaint = new Paint(Paint.FILTER_BITMAP_FLAG); //I also tried this
//PicturePaint = new Paint(Paint.ANTI_ALIAS_FLAG); //I also tried this
canvas.scale(Scale, Scale);
canvas.drawBitmap(CurrentPicture, 0, 0, PicturePaint);

我相信这是实现我的目标的最后障碍。我很担心,如果我不能解决图像质量问题,我就有麻烦了。感谢您的帮助。

谢谢!

系统不允许我发图片,所以下面是一个链接。

PictureSample

最佳答案

我不知道我的答案是否正确,我有一个 Canvas 代码。我希望这对您有所帮助。

public class FotosurpriseActivity extends Activity {
/** Called when the activity is first created. */
Bitmap overlay;
Paint pTouch;
int X = -100;
int Y = -100;
Canvas c2;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
Bitmap mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.android);
Bitmap mBitmapover = BitmapFactory.decodeResource(getResources(), R.drawable.ss);
overlay = BitmapFactory.decodeResource(getResources(), R.drawable.ss).copy(Config.ARGB_8888, true);
c2 = new Canvas(overlay);

pTouch = new Paint(Paint.ANTI_ALIAS_FLAG);
// pTouch.setXfermode(new PorterDuffXfermode(Mode.TARGET);
pTouch.setColor(Color.TRANSPARENT);
pTouch.setMaskFilter(new BlurMaskFilter(15, Blur.NORMAL));
setContentView(new BitMapView(this, mBitmap, mBitmapover));
}

class BitMapView extends View {
Bitmap mBitmap = null;
Bitmap mBitmapover = null;

public BitMapView(Context context, Bitmap bm, Bitmap bmover) {
super(context);
mBitmap = bm;
mBitmapover = bmover;
}

@Override
public boolean onTouchEvent(MotionEvent ev) {

switch (ev.getAction()) {

case MotionEvent.ACTION_DOWN: {

X = (int) ev.getX();
Y = (int) ev.getY();
invalidate();

break;
}

case MotionEvent.ACTION_MOVE: {

X = (int) ev.getX();
Y = (int) ev.getY();
invalidate();
break;

}

case MotionEvent.ACTION_UP:

break;

}
return true;
}

@Override
protected void onDraw(Canvas canvas) {
// called when view is drawn
Paint paint = new Paint();
paint.setFilterBitmap(true);
// The image will be scaled so it will fill the width, and the
// height will preserve the image’s aspect ration
/*
* double aspectRatio = ((double) mBitmap.getWidth()) /
* mBitmap.getHeight(); Rect dest = new Rect(0, 0,
* this.getWidth(),(int) (this.getHeight() / aspectRatio)); double
* aspectRatio2 = ((double) mBitmapover.getWidth()) /
* mBitmapover.getHeight(); Rect dest2 = new Rect(0, 0,
* this.getWidth(),(int) (this.getHeight() / aspectRatio2));
* canvas.drawBitmap(mBitmap, null, dest, paint);
* canvas.drawBitmap(mBitmapover, null, dest2, paint);
*/

// draw background
canvas.drawBitmap(mBitmap, 0, 0, null);
// copy the default overlay into temporary overlay and punch a hole
// in it
c2.drawBitmap(mBitmapover, 0, 0, null); // exclude this line to show
// all as you draw
c2.drawCircle(X, Y, 80, pTouch);
// draw the overlay over the background
canvas.drawBitmap(overlay, 0, 0, null);
}
}

}

关于android - 使用 Canvas 和 canvas.scale(Scale, Scale) 的图像质量问题;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8958082/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com