2012-01-22 3 views
1

Canvas 및 canvas.scale (Scale, Scale)을 사용하여 이미지 품질 문제가 발생했습니다.Canvas 및 canvas.scale (스케일, 스케일)을 사용하여 이미지 화질 문제;

안드로이드 : 그들은 정확히 다음과 같이 실행

내가 비트 맵을 다시 크기를 조정할 때 나는 이미지 품질 문제의 모든 게시물을 읽고 생각하지만, 도움이하지 않는 것으로 크기를 조정할 이미지의 품질 Canvas 축척 (float 축척)으로 축척 할 때.

이미지 품질 게시물에서 제안한 여러 가지 옵션을 시도했습니다.

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

답변

3

내 대답은 올바른에 상관하지 않습니다 여부를 내가 캔버스의 코드가 있습니다. 이게 당신을 도울 수 있기를 바랍니다.

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); 
     } 
    } 

} 
+1

코드를 제공해 주셔서 감사합니다. 정말 감사. 나는 그것이 효과가 있다고 믿는다. 시도했을 때 용의자가 됨 PicturePaint = new Paint (Paint.FILTER_BITMAP_FLAG); PicturePaint = 새로운 PaintPaint.ANTI_ALIAS_FLAG); 비트 맵을 Bitmap.Config.ARGB_8888로 설정하지 않았습니다. – user1133277

+0

ok ................... – Ramz

0

당신이 말하는 품질 문제를 보여주는 스크린 샷이 있습니까? 그림판에서 필터링이 활성화되어 있으면 괜찮을 것입니다.

+0

답장을 보내 주셔서 감사합니다. 답장 지연에 대해 사과드립니다. 나는 휴식을 취하고 뇌가 부풀어 오르게해야했습니다. 시스템에서 사진을 게시 할 수 없으므로 사진 샘플에 대한 링크를 추가했습니다. 내가받은 다른 답변을 검토하고 의견이 도움이되는지 확인하겠습니다. – user1133277

0

많은 코드를 시도했습니다. 방금이 내용을 내 매니페스트에 추가하면 최고 품질의 이미지를 얻었습니다.

저는 캔버스가 저해상도로 만들어 졌다고 생각합니다. 당신이 장치의 해상도를 화면에 인쇄하려고하면, 그것이 틀렸다는 것을 알 수 있습니다. 매니페스트의 추가로 해상도가 변경됩니다.

관련 문제