android image serialization transparent png

As a .net developer, new to android, I'm trying to consume images from my asmx webservice. Images are saved in the db as nvarchar (bytearray), so my webservice returns a string that can be converted into bitmap. This all works fine but I run into problems trying to get png images with transparent parts in it. No matter what I try, the transparent parts are always white. The problem is, there could be a couple of things I'm doing wrong here...

This is the way I write my png to db (c#) (it could be I'm losing transparancy here already?):

Image toAdd = Image.FromFile(@"I:\Andoid\h1graph.png"); string imagestring = System.Convert.ToBase64String(imageToByteArray(toAdd));

And this is the way I consume it on my android app :

Bitmap bmp; androidHttpTransport.call(SOAP_ACTION, envelope); SoapPrimitive resultsRequestSOAP = (SoapPrimitive) envelope.getResponse(); String result = resultsRequestSOAP.toString(); if (!result.equals("")) { byte[] bloc = Base64.decode(result, Base64.DEFAULT); bmp = BitmapFactory.decodeByteArray(bloc, 0, bloc.length); bmp.setHasAlpha(true); ByteArrayOutputStream os = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.PNG, 100, os); byte[] bloc2 = os.toByteArray(); Bitmap bPNGCompress = BitmapFactory.decodeByteArray(bloc2, 0, bloc2.length); viewModel.setThreeD(bPNGCompress) ; }

I've stripped the code so only the essential code is there. So, this works but it doesn't keep transparency.

I'm guessing, it's because the BitmapFactory.DecodeByteArray creates a bitmap without transparency, and so the rest of the conversion code won't create transparency.

I'm struggling for days now, trying to find solutions but I don't seem to find it. There must be a best practice for consuming png images from a webservice, serialized as string (?).

Using png from the resources, works ok with transparency, so I know my png is transparent and my UI controls are ok. (I know the coding is not state of the art but to avoid having to copy paste all kinds of methods, I replaced some code, that is normally in methods, to make it more readable)

I'm at the start of a project, experimenting with android, so If anyone has a completely different idea on how te get images into my app, be free to post ideas.

-------------Problems Reply------------

Try explicit alpha configuration for the decode operation:

BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inPreferredConfig = Bitmap.Config.ARGB_8888;

//and then call decodeByteArray with the explicit alpha option:

bmp = BitmapFactory.decodeByteArray(bloc, 0, bloc.length, opts);

//and then apply the same options to the compressed bmp version:

Bitmap bPNGCompress = BitmapFactory.decodeByteArray(bloc2, 0, bloc2.length);

Update I have written a simple test app to test the code and it works correctly (ie, has transparency). It's 100% that you lost the ALPHA bits before processing the image.

Placeholder layout:

<ImageView android:background="#FF0000" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageView" android:layout_marginTop="135dp" />

Code: ImageView imageView = (ImageView) findViewById(R.id.imageView);

byte[] imgData = Base64.decode("iVBORw0KGgoAAAANSUhEUgAAAJIAAACSCAMAAACZpWO8AAAC0FBMVEWioqKioqKioqKioqKioqKioqKmpqaurq6urq6tra2urq6urq6lpaWkpKSurq6urq6urq6lpaWurq6urq6urq6urq6lpaWurq6pqamurq6urq6urq6urq6urq6oqKiurq6tra2urq6urq6rq6uurq6mpqaurq6urq6urq6urq6urq6urq6urq6np6eurq6kpKSjo6Opqamurq6urq6urq6urq6urq6urq6urq6ioqKkpKSpqamurq6urq6urq6urq6qqqqurq6urq6urq6srKyurq6mpqaurq6urq6urq6urq6tra2lpaWurq6urq6urq6urq6urq6urq6urq6urq6oqKiurq6oqKiurq6lpaWurq6urq6np6eurq6urq6urq6urq6urq6urq6urq6pqamurq6urq6urq6urq6srKyurq6urq6jo6Ourq6urq6urq6urq6urq6oqKioqKinp6eqqqqnp6eurq6urq6urq6pqamurq6urq6urq6urq6rq6uqqqqkpKSurq6urq6np6eurq6urq6urq6urq6jo6Ourq6urq6urq6urq6lpaWurq6urq6qqqqurq6urq6urq6urq6urq6jo6OkpKSurq6urq6urq6urq6srKympqaurq6urq6rq6uioqKurq6urq6urq6srKyjo6Ourq6urq6kpKSkpKSurq6urq6srKyurq6np6eurq6urq6lpaWurq6urq6urq6urq6mpqampqalpaWurq6pqamurq6urq6urq6urq6kpKSkpKSjo6Ourq6urq6urq6jo6Ourq6urq6urq6urq6np6erq6uurq6urq6mpqaurq6urq6urq6urq6urq6urq6urq6jo6Ourq6urq6urq6urq6urq6urq6urq6urq6qqqqjo6Ourq6jo6MAAACmpqaoqKiqq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4KbTXA33sUIU+RihUDULRSvVvaKqcxRT9OdZPWDs1QYMefMYUOLUFLqLkJi0xvZx7RUjRnFuajhPK1nqyfSZDYmZC0IH3ST40e2EVkI7FAyZeQEBuHHBZKcBozxVcbUdKglqIArpP0aXarYa6m1Vr1nM5b878C255wkkpmo0xlOQAU5ggl3xgtcZDqteHniEhKxyNdoNGHVXlTScFb30MVgVor2KxJRHmK/aaR6PBEp0+mqiBUkm62tqdlWs9EhdLxLkI9foqHpMsdPpQQmVFKsOSbws0+hyb4+BlkJHQ4fVUw7vyTPavxuTVNu1vLL3mjqt5h4iyyjErU4hMEI/hVsQCblhkyFUVkgFoyO1vv45zU0laH+WUI3ioJL107S/JDuP8ZLsWZNVDUGsF3e1K6HxdH3duc9MVKXNyXXRyalp+l649meljmuMGu1hpPNd+XpfS9/fl/We/C0jmYiT+zDN4YH6X96PTsIMRmw/qvNpvSURMyi2GlniIKozZpHR5bzmoM1S1IudDd4ZZWwhiKwz7ERu0+S5dzXdZJX72D/QXGF8uYx8Xsa74ebe/sIsQMlp34IG3nIZe8wsKuJTj7nkrJ3Rib2oSOSamzlyFxWBOKc7sIAmR9KGE19sL/cffPB0f//yI76n6ovFS6+cW2YxvUDNjg5YIgcuSlnGZ88IWULF22QtdlRXqcgQyqmsk7gklD10kFmh4NczJS+cZQvNMSPkCLV5Y3mx3HtGhXYHXvDSImx1t+ob9Ps8Doqs9eZSdR+GFLj1+LgLQkq9v8ZgcsValzYf17rAWS9q2cPM8SuPe1z28OVh1he7OKQl82Bsh4Bq1uKQh4s7xB4Ed7xsJTFV1qJOiyd1fyNsV79dhWErxo1ZNryotOQRMsP/AJOx8xdiPgHbAAAAAElFTkSuQmCC", Base64.DEFAULT);
Bitmap bmp = BitmapFactory.decodeByteArray(imgData, 0, imgData.length);

ByteArrayOutputStream os = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, os);

byte[] compressedData = os.toByteArray();

Bitmap bPNGCompress = BitmapFactory.decodeByteArray(compressedData, 0, compressedData.length);

imageView.setImageBitmap(bPNGCompress);`

Category:android Views:3 Time:2019-02-02

Related post

  • css3 border-image's transparent png issue 2010-10-29

    I'm using border-image with a PNG image that has a transparent section. The issue is that the div has background-color set the black. When I apply border-radius, the transparent section of the pattern shows the black of the div and not the background

  • converting jpeg image to transparent png image 2012-01-13

    I have an image with text and white background. I want to retain the text, i want to create a png image with that text and a transparent background. Could anyone guide me. Thank u. --------------Solutions------------- I hope this will guide you to wh

  • Transparent PNG in PictureBox 2009-11-23

    Hi I am trying to make simple app that allows one to compare image to transparent PNG templates, by dragging the template over picture. For this I need a way to create a PictureBox that will contain the PNG image and be transparent where the the png

  • How to give outer glow to an object in a transparent png using CSS3? 2012-01-01

    I'm working on a project where I need to make modifications in more then 500 images to give outerglow on hover effect. I will need to modify each image to give the outer glow. It will be a very time consuming task. This is example of one image. All i

  • Quality of rendering shadow in transparent png on Android 2011-01-13

    When using a transparent PNG image which has a fine fading shadow always there is an edge line around the shadow on the Android screen. It does not show this in emualator or Exclipse. See photo. I wonder if there is way to improve on this. Is this so

  • flash cs5 transparent png issue on android screens 2012-03-03

    I am creating images in Photoshop with a transparent background. I am calling them into flash dynamically with actionscript 3 but the transparency has a white ghostly look to them. I can see the boxes move around on my ANDROID devices. I found this t

  • android: Images as buttons with transparency on SurfaceView with MediaPlayer 2012-04-03

    I have framed layout with ImageView, SurfaceView and control elements as overlaying ImageView. So, a SurfaceView is used to play media with MediaPlayer, and ImageView is used then MediaPlayer preparing media as a still image. Then OnPrepared ImageVie

  • DotNetNuke using PNG images with Transparency 2008-09-05

    I have a DotNetNuke site where my main logo is a PNG file using transparency. I tried GIF but the quality wasn't good enough. Anyways it worked great on IE7 but I just saw my site in IE6 and noticed that the transparency isn't working with my logo. D

  • How to use semi-transparent png images in IE6 2009-05-07

    How can I use semi-transparent png images in IE6? --------------Solutions------------- In fact you can using IE6 PNG Fix. There are some limitations, but overall, it works just fine. I have to say I prefer DD_belatedPNG over supersleight. It's way ea

  • Transparent PNG not working in SQL Server Image field 2009-05-28

    I have tried uploading a transparent PNG image to a SQL server image field, and retrieving it using the DynamicData ImageHandler. The Transparent areas in the image appear white upon rendering. Please advise about any solutions --------------Solution

  • How to merge transparent PNG with image using PHP? 2009-09-08

    The situation is this: I have a small 50x50 pic. I also have a small 50x50 transparent picture which contains a frame for the 50x50 pic, so I basically want to put the transparent png on top of the image and merge those two which would lead to a fina

  • Combine 2-3 transparent PNG images on top of each other with PHP 2009-09-09

    I am working on a custom avatar system for a project, but I have never really done much with the image side of PHP. I assume I need to use GD in some way, but I have no idea where to even start. Basically, there are a bunch of pre-made transparent PN

  • Transparent PNG as Background Image 2009-11-09

    I have an element with a transparent png as its background image - it's like a polaroid with the photo bit cut out so just the frame is showing. With this as the background I then want a standard image to sit behind the element that has the transpare

  • PNG image with transparency on SWT 2009-12-02

    I've got a Composite and would like to use a png file as background image. I can do that, the problem is when the image uses transparency it doesn't work and shows a white colour instead. Any thoughts on how to get this to work? Thanks! -------------

  • PHP Script to resize transparent png images 2010-04-06

    Could anyone link me to a sample script that would allow be to resize PNG images containing transparency? Some scripts I tried create a black area in place where the image was transparent. --------------Solutions------------- http://github.com/maxim/

  • How to overlay a transparent PNG over an image /when rolling over some other item/ 2010-08-02

    I have a webpage with a content image. On this image, I want to highlight a few different items, triggered by the user rolling over the corresponding item in the text on the same page. I have transparent PNGs that I can use as image overlays to accom

  • How to tint a transparent PNG image in iPhone? 2010-08-18

    I know it's possible to tint a rectangular image by drawing a CGContextFillRect over it and setting the blend mode. However, I can't figure out how to do a tint on a transparent image such as an icon. It must be possible since the SDK does it itself

  • Combine 4 transparent PNG images on top of each other in an ASP.NET environment 2010-10-08

    I came across the solution I need in PHP but I need one that I can use that's just as simple in an ASP.NET environment. I am combining 4 transparent png images to create a single image (Lets say its a custom certificate) with one of 4 background imag

  • How can I convert a JPEG image to a PNG one with transparent background? 2010-10-11

    I have a JPEG format image, with a white background and a black circle. How can I transform this image to a PNG format that the white background will be transparent and the black remains there? I'm a programmer too, and if there are some ideas in C#

  • Transparent png not showing bg image just bg color in html 2010-10-29

    I have a logo that is a transparent png and i want to overlay it on my bg image but when i do it shows only the background color. Here is an example: I am using a modified copy of the WP theme Colourise The Css is here: http://files01.s0urc3.ismywebs

  • How can I rotate a transparent png by 45 degrees using imagemagick and keep the new image transparent? 2010-11-08

    I have a 16x16 transparent png and I did convert -rotate -45 a.png b.png This rotated it and created a new image b.png which is of size 22x22 and which when I use against a background shows the original image (16x16) rotated with the underlying backg

  • Merging multiple transparent PNG images with php 2011-01-03

    I'm having a slight problem merging multiple transparent pngs on top of each other. I'm trying to create a tool that designs a belt on the screen for the user allowing them to select a strap, buckle, and design crease. The tool will merge three diffe

  • Transparent PNG image with TImageList 2011-01-27

    I'm using Delphi XE. I added a TAdvGlowButton on my form and added a TImageList with one transparent PNG image as its source for images. When I view the form in the design mode, the button looks exactly right and the image is transparent. However, wh

  • Android Transparent png doesn't show as transparent 2011-02-07

    I'm using an image with transparency as a ImageButton in my Android app - but when it appears on the android screen - it still has a whitish surrounding border. I even changed the image to one of the template ones supplied and that still is not trans

  • How to merge a transparent png image with another image using PIL 2011-03-16

    I have a transparent png image "foo.png" and I've opened another image with im = Image.open("foo2.png"); now what i need is to merge foo.png with foo2.png. ( foo.png contains some text and I want to print that text on foo2.png ) --------------Solutio

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.666 (s). 11 q(s)