2011-02-27 12 views
11

मैं एक कोड का उपयोग कर रहा हूं जो कैनवास का उपयोग कर छवियों में 1 को जोड़ती है। मैं छवि को छवि दृश्य में दिखाता हूं यह ठीक दिखता है। लेकिन जब मैं इसे वेबव्यू में दिखाने की कोशिश करता हूं तो यह उस छवि के दाईं ओर पृष्ठभूमि काली दिखाता है। मैं HTML में पृष्ठभूमि रंग बदलने की कोशिश करता हूं लेकिन यह रंग नहीं बदलता है। या पारदर्शी बनाओ। क्या कोई मदद कर सकता है? Result is here उपरोक्त छवि ImageView में है और नीचे WebView में है।एंड्रॉइड में वेबव्यू पर काले पृष्ठभूमि दिखाते हुए बेस 64 स्ट्रिंग को बिटमैप क्यों?

public class MyBimapTest extends Activity { 
/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    ImageView img1 = (ImageView) findViewById(R.id.ImageView01); 

    img1.setVisibility(View.INVISIBLE); 
    Drawable dra1 = img1.getDrawable(); 
    Bitmap map1 = ((BitmapDrawable) dra1).getBitmap(); 
    ImageView img2 = (ImageView) findViewById(R.id.ImageView02); 
    img2.setVisibility(View.INVISIBLE); 
    Drawable dra2 = img2.getDrawable(); 
    Bitmap map2 = ((BitmapDrawable) dra2).getBitmap(); 

    // *** 
    ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
    map1.compress(Bitmap.CompressFormat.JPEG, 100, baos); 

    byte[] b = baos.toByteArray(); 
    String abc = Base64.encodeBytes(b); 

    byte[] byt = null; 
    try { 
     byt = Base64.decode(abc); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
    map1 = BitmapFactory.decodeByteArray(byt, 0, byt.length); 

    // *** 
    Bitmap map = combineImages(map1, map2); 
    ByteArrayOutputStream bbb = new ByteArrayOutputStream(); 
    map.compress(Bitmap.CompressFormat.JPEG, 100, bbb); 

    byte[] bit = bbb.toByteArray(); 

    String imgToString = Base64.encodeBytes(bit); 

    String imgTag = "<img src='data:image/jpg;base64," + imgToString 
      + "' align='left' bgcolor='ff0000'/>"; 

    WebView webView = (WebView) findViewById(R.id.storyView); 
    webView.loadData(imgTag, "text/html", "utf-8"); 
    Drawable end = new BitmapDrawable(map); 

    ImageView img3 = (ImageView) findViewById(R.id.ImageView03); 
    img3.setImageBitmap(map); 
} 

public Bitmap combineImages(Bitmap c, Bitmap s) { 
    Bitmap cs = null; 
    int width, height = 0; 

    width = c.getWidth() + (s.getWidth()/2); 
    height = c.getHeight() + (s.getHeight()/2); 

    cs = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); 

    Canvas comboImage = new Canvas(cs); 

    comboImage.drawBitmap(c, 0f, 0f, null); 
    comboImage.drawBitmap(s, c.getWidth() - (s.getWidth()/2), c 
      .getHeight() 
      - (s.getHeight()/2), null); 
    return cs; 
} 

}

उत्तर

21

JPEG प्रारूप अल्फा पारदर्शिता, जिसके कारण पारदर्शी पृष्ठभूमि काला हो जाता है जब आप JPEG करने के लिए अपने मूल छवि परिवर्तित समर्थन नहीं करता।

map1.compress(Bitmap.CompressFormat.PNG, 100, baos); 

और

String imgTag = "<img src='data:image/png;base64," + imgToString    
    + "' align='left' bgcolor='ff0000'/>"; 
+0

आप को महान धन्यवाद:

बजाय PNG स्वरूप का उपयोग करें। यह पूरी तरह से काम करता है ... – Arslan

+0

बहुत बहुत धन्यवाद ... पहले संपीड़न प्रारूप जेपीईजी का उपयोग कर रहा था। यहां अधिक जानकारी प्राप्त करें http://developer.android.com/reference/android/graphics/Bitmap.CompressFormat.html – CoDe

+0

संपीड़न तक सही जवाब() हालांकि, imgTag कहां लागू करें? क्या आप मेरी मदद कर सकते हैं? – VVB

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