2012-04-16 34 views
7

मैं एक ऐप बनाने की कोशिश कर रहा हूं जो आपके द्वारा संपादन टेक्स्ट के माध्यम से निर्दिष्ट दो चित्रों को ले जाएगा, दोनों छवियों पर प्रत्येक पिक्सेल के रंगों की तुलना करें और एक नई तस्वीर (बिटमैप) बनाएं (आप एसडी कार्ड में सहेज सकते हैं) जिसमें दो मूल चित्रों के बीच मतभेद शामिल हैं।एक नया बिटमैप बनाएं और इसमें नए पिक्सल बनाएं

मुझे यह नया बिटमैप बनाने में कोई समस्या है। मैं अपना लक्ष्य कैसे प्राप्त कर सकता हूं? मुझे वास्तव में यह नहीं पता कि यह कैसे करना है, क्या मैं पहले नया बिटमैप बना देता हूं और फिर इसमें लिखता हूं, या क्या मुझे पहले मतभेद मिलते हैं और फिर उस से बिटमैप खींचते हैं? चित्र लगभग होंगे। 300x300 पीएक्स।

उत्तर

14

इस कोड को सिर्फ मेरे सिर और untested से बाहर है, लेकिन यह सही रास्ते पर आप मिलना चाहिए: यहाँ एक उदाहरण है।

final int w1 = b1.getWidth(); 
final int w2 = b2.getWidth(); 
final int h1 = b1.getHeight(); 
final int h2 = b2.getHeight(); 
final int w = Math.max(w1, w2); 
final int h = Math.max(h2, h2); 

Bitmap compare = Bitmap.createBitmap(w, h, Config.ARGB_8888); 

int color1, color2, a, r, g, b; 

for (int x = 0; x < w; x++) { 
    for (int y = 0; y < h; y++) { 
     if (x < w1 && y < h1) { 
      color1 = b1.getPixel(x, y); 
     } else { 
      color1 = Color.BLACK; 
     } 
     if (x < w2 && y < h2) { 
      color2 = b2.getPixel(x, y); 
     } else { 
      color2 = Color.BLACK; 
     } 
     a = Math.abs(Color.alpha(color1) - Color.alpha(color2)); 
     r = Math.abs(Color.red(color1) - Color.red(color2)); 
     g = Math.abs(Color.green(color1) - Color.green(color2)); 
     b = Math.abs(Color.blue(color1) - Color.blue(color1)); 

     compare.setPixel(x, y, Color.argb(a, r, g, b)); 
    } 
} 
b1.recycle(); 
b2.recycle(); 
0

मैं पहले बिटमैप बनाउंगा और प्रत्येक पिक्सेल के बीच मतभेदों की गणना करूंगा, लेकिन आप पहले मतभेदों की गणना करने के लिए स्वागत करते हैं और फिर बिटमैप.copyPixels का उपयोग करते हैं, लेकिन मुझे लगता है कि यह पहली तरह समझना आसान है।

// Load the two bitmaps 
Bitmap input1 = BitmapFactory.decodeFile(/*first input filename*/); 
Bitmap input2 = BitmapFactory.decodeFile(/*second input filename*/); 
// Create a new bitmap. Note you'll need to handle the case when the two input 
// bitmaps are not the same size. For this example I'm assuming both are the 
// same size 
Bitmap differenceBitmap = Bitmap.createBitmap(input1.getWidth(), 
    input1.getHeight(), Bitmap.Config.ARGB_8888); 
// Iterate through each pixel in the difference bitmap 
for(int x = 0; x < /*bitmap width*/; x++) 
{ 
    for(int y = 0; y < /*bitmap height*/; y++) 
    { 
     int color1 = input1.getPixel(x, y); 
     int color2 = input2.getPixel(x, y); 
     int difference = // Compute the difference between pixels here 
     // Set the color of the pixel in the difference bitmap 
     differenceBitmap.setPixel(x, y, difference); 
    } 
} 
संबंधित मुद्दे