Unity3d 4.6 UI Image bug on some Windows 8 and 8.1 - user-interface

I'm making an interactive book for windows users and i'm using 4.6 UI system. I tested my application on lots of computers using various windows versions. It works fine with windows xp, windows 7, windows 8 and 8.1. But some of the windows 8 and 8.1 computers are producing a weird bug.
Here is how it should look like
and here it is in windows 8
Btw i have lots of images in my application. I'm putting them in my project with .bytes extension and creating sprite on runtime. My code to do this is :
void TextAssetToSprite(int pNo)
{
TextAsset tmp = textAssetArray[pNo] as TextAsset;
Texture2D imgTexture = new Texture2D(1, 1);
imgTexture.LoadImage(tmp.bytes);
Rect rectangle = new Rect(0, 0, imgTexture.width, imgTexture.height);
Vector2 pivot = new Vector2(0.5f, 0.5f);
Sprite firstSprite = Sprite.Create(imgTexture, rectangle, pivot);
imageControl.sprite = firstSprite;
tmp = null;
imgTexture = null;
Resources.UnloadUnusedAssets();
}
I don't know what i'm doing wrong. I've done hours of research but found nothing similar. When i create sprite in the editor and use it on UI image component it works as expected but it's not an option because there are lots of png images in my application and it's size will be too much. Please suggest me a way to fix this. Any help will be greatly appreciated.

It's been a long time since I posted this. I don't know if unity fixed the issue or not. Problem was when I was creating the Texture2D I was just giving it width and height parameters but some operating systems change the default settings for Texture2D. So here is the solution. Change
Texture2D imgTexture = new Texture2D(1, 1);
to
Texture2D imgTexture = new Texture2D(2, 2, TextureFormat.RGB24, false);

Related

How to enable GPU for SkiaSharp GL

I'm using this code in constructor of MainPage (which is devired from ContentPage):
canvasView = new SKGLView();
canvasView.PaintSurface += OnCanvasViewPaintSurface;
canvasView.EnableTouchEvents = true;
canvasView.Touch += OnTouch;
Content = canvasView;
I somehow have the feeling that GPU is not used, because with many shapes in the canvas it begins to lag quite soon.
I've tried to enable GPU by using
var GPUContext = GRContext.CreateGl();
var gpuSurface = SKSurface.Create(GPUContext, true, new SKImageInfo(500, 500));
before creating the SKGLView but the GPUContext is null.
What am I'm doing wrong?
Can someone give an example how to properly enable GPU for SkiaSharp?
My longterm goal is to develop an app for iOS and Android, but for practically reasons I'm currently developing for Windows. I assume, GPU can also be used on mobile devices, right?

GDI changes my Font to MS Sans Serif, if code is executed in Non-UI-Application

I have a method which generates images using DrawString(). If I call this method on every machine I tested from any program with an UI or from Console-App every thing is fine. The image shows the right font.
But if I call this method from windows service or from IIS website GDI (?) automatically changes to Microsoft Sans Serif without any exception.
It was working for years on Windows 7. After change to Windows Server 2019 the problem occurs first time. Now I have 2 developer machines with Windows 10 Build 20H2 and the same .NET versions on both. On one machine image generation works well, on the other machine the font changes. Any idea, what I can do, to get it work on every machine?
public void GenerateBitmap()
{
string drawString = "Sample Text 1234567890";
using (Bitmap bmp = new Bitmap(5000, 200, PixelFormat.Format32bppArgb))
{
bmp.SetResolution(300, 300);
using (Graphics grfx = Graphics.FromImage(bmp))
{
using (Brush brush = new SolidBrush(Color.Black))
{
Font f = new Font("MyFontName", 22F);
grfx.DrawString(drawString, f, brush, new Point(0, 0));
}
}
bmp.Save("test.png", System.Drawing.Imaging.ImageFormat.Png);
bmp.Dispose();
}
}

Best way to show many mini versions of painted InkCanvas in UWP

I have a problem to depict many mini-versions of my InkCanvas. In my app it is possible to write or draw on a InkCanvas. Now I want to depict all created InkCanvas in a GridView.
But with mini versions in this GridView i can not create enough mini versions.
I tested it with 36 mini versions and after I show one and navigate back, the App crashs everytime by rendering the same mini InkCanvas with the error: Insufficient Memory. So I searched an found this post:
Insufficient memory to continue the execution of the program when trying to initialize array of InkCanvas in UWP
I checked the Memory workload:
var AppUsageLevel = MemoryManager.AppMemoryUsageLevel;
var AppMemoryLimit = MemoryManager.AppMemoryUsageLimit;
and the memory has enough free space. (is this a bug?)
So I tried to render a image from my grid with a InkCanvas but the strokes were not rendered and all pictures were empty. ( can I save Memory this way?)
So now my question is:
Can someone tell me how to solve this problem? And what is the best way?
Thank you very much in advance!
Agredo
If you want to preview your drawings, better way is to render them to bitmap and show this bitmaps in grid instead of multiple complex controls InkCanvas is.
Here is some code to render inks to bitmap from another SO Answer:
CanvasDevice device = CanvasDevice.GetSharedDevice();
CanvasRenderTarget renderTarget = new CanvasRenderTarget(device, (int)inkCanvas.ActualWidth, (int)inkCanvas.ActualHeight, 96);
using (var ds = renderTarget.CreateDrawingSession())
{
ds.Clear(Colors.White);
ds.DrawInk(inkCanvas.InkPresenter.StrokeContainer.GetStrokes());
}
using (var fileStream = await file.OpenAsync(FileAccessMode.ReadWrite))
await renderTarget.SaveAsync(fileStream, CanvasBitmapFileFormat.Jpeg, 1f);
You also need to add Win2D.uwp nuget package to your project.

OpenCV trackbar performance in OSX

I've just noticed that performance of openCV is drastically slowed down when a trackbar is present in a window with changing image from camera or a movie frame. What could be done resolve this issue?
The solution to that is to move trackbars to a separate window. For me on OSX the performance increased 4.7 times (from 3 FPS up to 14). I don't know if it works like this always or it's just like that on my computer but I haven't seen such a clue anywhere before so I decided to share.
string title = "My window";
int p = 2;
// Create a different window for controls
namedWindow(title + " - controls");
// I show an image once just to resize the window
imshow(title + " - controls", Mat::zeros(1, 500, CV_8UC1));
createTrackbar("Parameter", title + " - controls", &p, 3);
// Create a different window for actual image
namedWindow(title);
while (!done) {
// Do some calculations
flip(image, image, p);
imshow(title, image);
}
I also encountered the same problem in OSX-10.9.
And I have resolved the issue in the following ways:
port variants opencv
sudo port install opencv +qt4 +tbb +eigen +opencl
important option is "+qt4" only, the other options are extra.
OpenCV support Qt for GUI backend. And I suspect the cause of the problem is in the implementation of the default GUI backend.
I was able to virtually eliminates the problem by re-build OpenCV library with Qt support and re-install(update).
For me, this seemed to be an issue with the Anaconda distribution of OpenCV.
Installing OpenCV with pip fixed my performance issues.
Try to tune
cv2.waitKey(value)
I used cv2.waitKey(100) and works smoothly

Why do my Windows Forms strings look so ugly when anti-aliased?

I'm rendering some strings manually on top of a GraphicsBox, because you can't have a Label with a treansparent backdrop.
No matter which rendering mode I try though, I can't get the strings to look any good (ie. as they would appear in Word or in a graphics program.
Here's a picture of the interface mockup compared to what renders onscreen:
Unfortunately StackOverflow seems to shrink the picture so here's a direct link too: http://i.stack.imgur.com/vYFaF.png
And here's the code used to render:
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Graphics labelDrawing = e.Graphics;
labelDrawing.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
labelDrawing.DrawString("Setup Progress", new Font("Calibri", 10, FontStyle.Bold, GraphicsUnit.Point, 0), new SolidBrush(Color.Black), new Point(12, 9));
labelDrawing.DrawString("The following components are being configured.", new Font("Calibri", 10, FontStyle.Regular, GraphicsUnit.Point, 0), new SolidBrush(Color.Black), new Point(24, 27));
}
I've tried changing the TextRenderingHint to every option in turn, but no matter what I try if there's any antialiasing then it comes out in a blurry, smeared mess like in the screenshot. Any idea?
You can have transparent labels in .NET.
Check out this article on CodeProject on How to Use Transparent Images and Labels in Windows Forms
As for you drawing problem Calibri doesn't have a native font size of 10. You can verify this in Control Panel->Fonts. The smallest native font size is 12 (on my machine at least). Change you from size to 12 and you will see it's much better.
When you don't use native font sizes somewhere under the hood Windows/.NET/GDI+ will attempt to scale the font for you. This scaling is most likely causing your problem.

Resources