2012-01-06 22 views
5

पर एक ओवरले (छवि फ़िल्टर) को लागू करना मैं कैमरे के इरादे से एक छवि को कैप्चर करने की कोशिश कर रहा हूं और फिर उस पर एक छवि फ़िल्टर लागू कर रहा हूं। छवि को विस्तारित करने के लिए कैमरे द्वारा कैप्चर की गई एक छवि होगी और छवि फ़िल्टर संसाधनों में एक पीएनजी फ़ाइल के रूप में उपलब्ध होगा। मैं मूल छवि के शीर्ष पर फ़िल्टर ओवरले करने में सक्षम हूं। लेकिन, एक बार ओवरले-एड मूल छवि 'लगभग' अदृश्य है (जिसका अर्थ है कि फ़िल्टर मूल छवि पर स्थिर है और न केवल इसे बदल रहा है)। मेरी समस्या का वर्णन करने के लिए मेरे पास कुछ छवियां हैं I पहली छवि फ़ोटोशॉप में थी - जब मैंने एक छवि के शीर्ष पर एक फ़िल्टर रखा, तो यह ठीक लग रहा था। दूसरी छवि नीचे उद्धृत कोड द्वारा उत्पादित है - आप स्पष्ट रूप से देख सकते हैं कि फ़िल्टर प्रभाव गुम है। क्या किसी के पास कोई सुराग होगा कि ऐसा कुछ क्यों हो रहा है। क्या मुझे यहां कुछ तर्क याद आ रहा है?एक बिटमैप

Filterd Image - Photoshop

Filtered Image - via code

निम्नलिखित कोड मेरे पास है। अगर आप यहां किसी भी सर्वोत्तम प्रथाओं को याद करते हैं तो मैं क्षमा चाहता हूं। मैं शुरू में कोड का परीक्षण करने की कोशिश कर रहा हूँ:

mPictureView = (ImageView) findViewById(R.id.pictureView); 
filterButton = (Button) findViewById(R.id.filter_button1); 

// define the threshold fro scaling the image 
private final double SCALE_THRESHOLD = 6.0; 

// acquire the bitmap (photo captured) from the Camera Intent - the uri is 
// passed from a previous activity that accesses the camera and the current 
// activity is used to display the bitmap 
Uri imageUri = getIntent().getData(); 
Bitmap imageBitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri); 

// set the imageView in the current activity to display the picture retrieved 
// from the camera 
mPictureView.setImageBitmap(imageBitmap); 

// get the dimensions of the original bitmap 
int photoWidth = imageBitmap.getWidth(); 
int photoHeight = imageBitmap.getHeight(); 

filterButton.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View v) { 
    // set the options 
    Options options = new BitmapFactory.Options(); 
    options.inScaled = false; 
    options.inPreferredConfig = Bitmap.Config.ARGB_8888; 

    // get the image (png file) filter from resources using the options 
    Bitmap filter = BitmapFactory.decodeResource(getResources(), R.drawable.colorful_filter,options); 

    // create a scaled copy of the filter 
    Bitmap filtercopy = Bitmap.createScaledBitmap(filter, (int)(photoWidth/SCALE_THRESHOLD,(int)(photoHeight/SCALE_THRESHOLD), true); 

    // recycle the used bitmap 
    filter.recycle(); 
    filter = null; 

    // get a scaled, mutable copy of the orginial image 
    Bitmap imagecopy = Bitmap.createScaledBitmap(imageBitmap,(int)(photoWidth/SCALE_THRESHOLD), (int)(photoHeight/SCALE_THRESHOLD),true); 

    // recycle the used bitmap  
    imageBitmap.recycle(); 
    imageBitmap = null; 


    Paint paint = new Paint(); 
    paint.setAntiAlias(true); 

    //paint.setAlpha(230); - if a discrete value is set, then the image beneath 
    // the filter is visible. But, I don't understand why I need to do this. 
    // Besides, that reduces the efficacy of the filter 

    // create a canvas with the original image as the underlying image  
    Canvas canvas = new Canvas(imagecopy); 
    // now, draw the filter on top of the bitmap 
    canvas.drawBitmap(filtercopy, 0, 0, paint); 

    // recycle the used bitmap    
    filtercopy.recycle(); 
    filtercopy = null; 

    //set the filtered bitmap as the image 
    mPictureView.setImageBitmap(imagecopy); 

} 

संपादित करें 1: मैं लेख है कि Joru प्रदान की गई है की मदद से कुछ प्रगति करने के लिए सक्षम था। समस्या 2 बिटमैप्स के मिश्रण के साथ प्रतीत होती है। विधि ड्रॉ बिटमैप उस स्थिति में दूसरे पर एक बिटमैप खींच लेगा जो मेरे पास है। कोड की निम्न पंक्ति वास्तव में 2 बिटमैप्स को मिश्रित करने का प्रयास करेगी। मैंने एक छवि भी संलग्न की है जो मेरी प्रगति दर्शाती है। अंतर्निहित बिटमैप अब काफ़ी अधिक दिखाई देता है:

paint.setXfermode(new PorterDuffXfermode(Mode.MULTIPLY));  

मैं अभी भी कुछ समय के लिए यह के साथ चारों ओर खेलने के लिए वांछित आउटपुट को प्राप्त करने से पहले की है।Color Filter - Revisited

उत्तर

2

आप कुछ बातें की कोशिश कर सकते:

Bitmap new = old.copy(Config.ARGB_8888, true); 

यकीन है कि बिटमैप आप MediaStore से खोल रहे हैं कि प्रारूप में है बनाने के लिए। यदि ऐसा नहीं है, तो यह आपकी समस्या का कारण बन सकता है।

+0

प्रतिक्रिया के लिए धन्यवाद। मैंने पहले ही यह सुनिश्चित कर लिया है कि दोनों छवियां ARGB_8888 प्रारूप में हैं। ऐसा लगता है कि फ़िल्टर कुछ पारदर्शिता खो रहा है और मैं यह नहीं समझ सकता कि क्यों। – Abhijit

+0

इसे पढ़ना http://android.nakatome.net/2010/04/bitmap-basics.html सहायता का हो सकता है। – Joru

+1

यह आलेख बहुत उपयोगी था। मैंने अपने कोड में प्रस्तुत कुछ विचारों को शामिल किया है और इसने अभी तक सकारात्मक परिणाम नहीं दिखाए हैं। इसलिए, मैं इस पर काम करना जारी रखूंगा और जैसे ही मैं इसे समझता हूं, समाधान जारी रखूंगा। धन्यवाद फिर से - मैं आपका जवाब स्वीकार कर रहा हूं क्योंकि आपने मुझे सही दिशा में इंगित किया है। – Abhijit

संबंधित मुद्दे