XNA Texture2D.FromStream doesn't preserve color in fully transparent pixels - xna

I'm using the color information in the texture still when the alpha is set to 0. The PNG file is correctly saved with the color preserved. If I use the content pipeline and set it to non-premultiplied, everything works fine. Texture2D.FromStream is documented as non-premultiplied but it's wiping out the color. When debugging in PIX and looking at the texture, all pixels with 0 alpha are set to black.
Is there a way I can bypass the content pipeline and still keep my color for transparent pixels?

I'm not able to help too much just now as I don't have code in front of me but I done this a few days ago myself and it had all the correct transparency that was expected. Perhaps it's your image that has an issue? I used a PNG saved using Paint.Net.
As seen in this image http://imgur.com/Qrqqo the boat, tree trunk and ladder all have transparency which allow them to be on a second layer and the tileset itself is loaded using from stream (User generated content ftw).
So if no-one has answered this before I get to my computer with code then I'll take a look at what I have and post a sample if needed.

Related

Delphi 2007 - Loading TJvImage from a PNG file loses transparency

I have a couple of TJvImage components on my main form. One is loaded at design time from a partially transparent PNG file. The other is smaller than the first and in front of it. It is loaded at runtime with another partially transparent PNG file.
JvImage1.Picture.LoadFromFile ('Logo.png') ;
JvImage1.Transparent is set to TRUE. The problem is simple: the smaller image is rendered ignoring the alpha channel - i.e. it punches out the background image.
This does not occur when I load both images at design-time. They both show as partially transparent on the form, and display correctly when I run the program.
The real dilemma is that a minimal test program written to try to demonstrate the problem does not show the problem, but the same code in the application proper doesn't behave.
Is there anything about the underlying main form that could affect the behaviour?
I don't know if this is the same for TJvImage but when you set Transparent property of TImage to True it causes TImage to skip rendering any pixel with TransparentColor.
If no transparent color is set the color of lower left pixel is used.
When in such mode TImage doesen't take into accound alpha channel. Infact Transparency only works when you load TBitmap typed image into TImage.
I gues that TJvImage probably works in similar way. So in order to show your image properly you should set the Transparent property to False. This will probably alow TJvImage to render your picture by using Alpha transparency that is encoded to the picture itself.

XNA Strange blur on my transparency .png

(i can't post images so i posted links instead)
i'm working on a 2D platform game using pixelperfect.
The problem is about the png images used in-game. On transparency, there are some blur.
like this :
http://i.stack.imgur.com/lBX3A.jpg
If i open the texture with TheGimp, this is what i get :
http://i.stack.imgur.com/pOeF4.jpg
this is a sample of my map (zoom 1600x).
As you can see there is no blur around the black. (the grey squares means transparency).
Tests i did :
save without compression and re-opened it = no blur.
to be sure, i added a white background in gimp (it's easier to see the dark blur on white) :
(http://) i.stack.imgur.com/jfhWv.jpg
of course, i removed the white background because i wanted it transparency.
last information : there is blur on every transparency png images, even on my spritesheet character. When i animate it, i can see the blur from others frames.
After my tests, i concluded that gimp isn't the problem.
Can you help me ? Thx for reading.
xna4, c#2010 express edition, gimp2.611.
Sorry about my english ^^
This happens because of "texture filtering", which xna does by default.
You probaly can disable this.
found something: https://gamedev.stackexchange.com/questions/6820/how-do-i-disable-texture-filtering-for-sprite-scaling-in-xna-4-0

How to figure out, If an imagefile (base64) has transparency?

i wonder, how i could figure out if an image has a transparency effect applied. Is there any way in JavaScript or HTML5? I have a Base64-coded image. Is there a way to read out the transparency-information (alpha-channel). For example, if i load a PNG-Image, then convert it to base64, then drop it to html5-canvas, now how can i know if this has transparency-effect activated?
thanx alot
okyo
When you say 'drop it to html5-canvas', I assume you mean using an image element with the 'data:' URI scheme. Also, let's take it as given that you don't want to write javascript code to parse the image files.
You could do something like this pseudo-code:
create 2 off-screen canvases
color one opaque white and the other opaque black
draw the image on both of them
call getImageData on each canvas, using the image bounds
compare the image data
If the image has any transparent or partially-transparent pixels, then presumably the two canvases will end up at least a little different. One exception would be if the image has the transparency feature enabled but is entirely opaque anyway. Another would be if the non-opaque pixels are only very slightly transparent - not enough to alter a white or black background. But this technique would catch images where transparency is noticeable.

How to get great looking transparent PNGs on BlackBerry?

I am able to use PNGs that have drop shadows but the effect when displayed on the BlackBerry looks like it collapses the transparent channel down from its original smooth gradient to only several transparent values giving it a choppy look.
The same issue is encountered by drawing on the UI using BlackBerry fields or the graphics.drawBitmap method. Anyone want to share hints for getting great looking transparent effects on the BlackBerry?
Dither your images or pre-composite them. When loading an image on a BlackBerry, you get at most 4 bits of alpha data, which allows 4 bits each for RGB. So, if you want to dither your transparent images, go for RGB4444. If you don't dither them, that's what causes 8-bit alpha to just be mapped to the nearest 4-bit value.
If you include no alpha data (i.e., precomposite), you can get RGB565, which will have a better image quality overall, but you will have to deal with static positioning for your dropshadows.

Best way to programatically fill in a white border with a black border on images

I have over 100k in images that at one time were cropped and had a white border applied to them. I'm looking for the best way to programmaticly process each image so that I can detect the white borders and either crop the border or fill in the border with black instead. Would I need to use something like OpenCV or just plain old GDI? I've attached an image for reference.
What I have to work with (White borders are there, trust me):
http://cdn-images.hollywood.com/site/SO_3666231.jpg
Plain old GDI should work just fine, except for one thing - I don't know how to make GDI save an image back to a file. When I've had to do it in the past I've written a .BMP file in pieces, which wouldn't work for a JPEG. Time for a new question?
You're going to need a two step process - first measure the white borders, then copy the image to a new image to get rid of them.
Starting with a JPEG image introduces two small problems. First is that the image will contain some decoding artifacts, and white won't always be an RGB value of (255,255,255). You'll need to establish a threshold, such as (250,250,250) and see how that works; if it doesn't catch all of the borders, you'll need to try a lower threshold. Second is that resaving the image as a JPEG will introduce additional artifacts, lowering the quality of the image. Hopefully this will be within acceptable limits, but only you can be the judge of that.
I'm sorry that this isn't really an answer, perhaps more like 1/4 of an answer. I hope you find it useful.

Resources