Jump to content

[ Solved ] Blurred image


Recommended Posts

Hi

i'm writting a plugin for share vessels, and my last problem is all my images are blurred.

i have the same problem for image, button, application launcher button...

here i have tested with a mod logo (mechjeb), and i have the same issue (my plugin use the MJ logo in the right, its the same with all images)

blurred_image.png

here are others images of my mod, blurred too :s

blurred_image.png blurred_image.png

Someone have a idea ?

Thx

edit:

private WWW imgGM = new WWW("file://"+root+"Plugins/Textures/gm.png");

public static Texture2D buttonGM = new Texture2D(24, 24);

(its the same with other size)

and in my awake() method:

imgGM.LoadImageIntoTexture(buttonGM);

Edited by Zetla
Solved
Link to comment
Share on other sites

first thought, your images are created too small and get upscaled..

can that be the problem?

my stock toolbar buttons are 36x36px btw..

I thought it's the default..

new Texture2D(24, 24); will downscale all images to 24x24

It's likely this is the cause..

If that's the problem,

you may want to get the image original width/height first and create your Texture2D with these dimensions..

was just a guess, if I'm wrong, never mind..

Link to comment
Share on other sites

There is no need to load your image yourself. Anything in GameData and not inside a PluginData folder is loader by the game. If you load the image with code you get 2 copy loaded and waste some mem (not much for a small texture but still)

Just get your texture with

Texture tex = GameDatabase.Instance.GetTexture("MyAmazingMod/Plugins/Textures/gm", false);

As for the blur I don't know. philotical is right that the stock one are 32x32.

Link to comment
Share on other sites

Thx for your reply :)

when a load image into texture, the dimensions of the texture2D take the dimensions of the image

exemple:

public static Texture2D buttonGM = new Texture2D(1, 1);

and

imgGM.LoadImageIntoTexture(buttonGM);

at the final, the texture2D have the same dimensions of my image (38*38 for the application launcher)

(i have tested with the good dimensions and its the same)

for other image (button and foto), i just show image (i dont write dimensions of them)

exemple:

private WWW img = new WWW("file://" + GameManager.root + "/GameData/GameShare/PluginData/screenShots/screenTemp.png");

public static Texture2D screenTry = new Texture2D(320, 180);

img.LoadImageIntoTexture(screenTry);

and for show:

GUILayout.Box(screenTry, GUILayout.ExpandWidth(false));

so image appear with her native dimension

Sarbian, thx man, i go to change my code :)

Link to comment
Share on other sites

Sarbian, after change my code, my problem is partially solved!

now my application launcher button, and my button appear correctly

blurred_image.png

so i have the problem just for my foto

it's a plugin for share vessel, so i show informations of the shared vessel, and one screenshot.

so, screenshot was downloaded in game, and i think a need to load it, and after, use the 'LoadImageIntoTexture' method...?? (because game don't load when starting, and screenshot are in 'plugindata' folder)

Link to comment
Share on other sites

[Edit: ninjad - partially outdate]

You said shared vessel, so I thought you load vessel pics from a web server..

but as sarbian said, no need to use www if the pics are in game data..

However: your images are downscaled and re-upscaled somewhere - it's obviouse from the screenshots..

I might be wrong with "where" it happens - but these pictures have a scale issue - without seeing more code, it's hard to confirm - but my gutt says so lol

The fact, that even the MJ pic gets screwed up prooves that my belly is right this time.

that pic gets scaled down to at least it's half and displayed larger then the RAM texture is.

you can try it in any graphic progam, load the pic, scale it down, rescale it up - you will get that result..

good luck on debugging this - but keep looking for a scale issue..

Link to comment
Share on other sites

Using WWW is not an instant action. You either need to use "yield" to wait for the loading to be done or check www.done.

Or load by reading the file

Texture2D tex = null;

byte[] fileBinary = File.ReadAllBytes(filePath);

tex = new Texture2D(2, 2);

tex.LoadImage(fileBinary );

[code]

Link to comment
Share on other sites

i have the 2 screeshot:

the original screenshot (1280*720):

http://s7.postimg.org/v9wp4cqor/screen_Temp.png

and the downscale (320*180)

http://s21.postimg.org/ygheex89z/blurred_image.png

as you can see, the downscaled image quality is good, so its just a renderer issue..

EDIT:

i think a need to find other way to load a image..

That is not what I ment:

AFTER you load the image from the net, the c# code that creates your RAM texture does a rescale without you knowing it!!

That is what I mean..

What probably happens is this:

- pic has 200x200 on hard drive

- pic get's loaded by your script

- pic has 25x25 in RAM

- pic has 200x200 in GUI

- result blurry display..

your code has one faulty line, that does an unwanted rescale..

look for that or you'll search forever :-)

Link to comment
Share on other sites

This is all I know about it:

http://docs.unity3d.com/412/Documentation/ScriptReference/Texture2D.Texture2D.html

it looks as if you have a custom function named newTexture2D(320,180)

(or was that space ommitted newTexture vs. new Texture?)

my guess is, in that function newTexture, those numbers are ignored and the size of the texture is wrong..

Link to comment
Share on other sites

ok guy its working!

i just add the texture format to the texture2D

my code:

public static Texture2D screenTry = new Texture2D(320, 180, TextureFormat.ARGB32, false);

without texture format: blurred_image.png with texture format: blurred_image.png

thx very much to Philotical, and Sarbian, for give me the good way :)

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...