I am using Unity in my Android app. When the app opens, I show the user data in the Unity scene. User data contains texts and images.
In order to load this data in the scene, I make a lot of
UnityPlayer.UnitySendMessage(GameObject,Function,Params)
calls to many C# scripts in Unity from Android. Each of these calls performs a specific task like loading an image, creating a text, applying the text font etc.
Problem is that the loading of this data right now looks incremental (if that's the right word). So the text is visible first and after a fraction of a second the image shows. Some text effects show later. This looks ugly.
How can I make all the UI elements load at the same time even if it takes some time? Is there a way to freeze the scene before each game object is ready to be drawn so that user sees the final output as it should be and not as a series of UI element loading at different times.
Edit: On Android side, this is a simplified sample of how I make the calls
//I call these methods one after the other which make Unity calls
createText(textList)
createImages(imageList)
private fun createText(texts: List<Text>) {
for (text in texts) {
UnityPlayer.UnitySendMessage("Text", "CreateText", text.name+","+text.fontSize+","+text.bold)
}
}
private fun createImages(images: List<Image>) {
for (image in images) {
UnityPlayer.UnitySendMessage("Image", "CreateImage", image.name+","+image.url+","+image.size)
}
}
On Unity, I have the implementations for the same in different C# scripts. Something to note and my bad for not mentioning it is that Images are downloaded from a url which is passed to Unity as in the method above. That is what causes this lag in images showing up but I'm fine with that as long as everything else shows up at the same time.
I am writing a program that renders fractal images. It takes time to generate these images, and I want to monitor the progress of the program in real time.
Here is the structure of how I imagine my code should be structured:
// create a window to display the image as it gets rendered
CreateDisplayWindow();
// as long as you are not finished rendering the image,
while(!doneRendering)
{
// render a bit more of the image.
RenderASmallPartOfMyImage();
// update the screen if it has been too long since the last time it was updated.
if(timeSinceLastDisplayUpdate >= displayUpdatePeriod) UpdateDisplayWindow();
}
I have searched google and MSDN for hours trying to find a simple way of achieving this. I only find complicated answers. I imagine that the right answer will be very simple.
To summarize my question: How Do I create a "display window" that can be periodically updated that will not block the execution of my while(!doneRendering) loop?
In my application, there is an image uploading and if a user wants to upload gif image. I need to disable looping in an image and save it, in the result gif image of a user must be played once and stop after that. Maybe I need to delete pointer from the last frame of gif image? Any ideas?
You need to add or change the Netscape Application extension block. In this block there are 2 bytes to control the looping, see details in the following answer:
https://stackoverflow.com/a/28486261/3936440
I couldn't find a proper package for GIF manipulation but i think you can use BumpKit as an inspiration as mentioned here
https://stackoverflow.com/a/32810041/3936440
or
https://github.com/DataDink/Bumpkit/blob/master/BumpKit/BumpKit/GifEncoder.cs
I found an answer, thank you all who tried to helped me.
The gif image has a set of properties which you can get if you know the specific address of a byte of each property.
For example, 20737 is looping property.
if this property set to 0 gif image will have infinite looping, but if set this property great than 0 gif image will be repeated infinitely. The example I placed here.
var image = System.Drawing.Image.FromFile(path)
var IsLooped = BitConverter.ToInt16(image.GetPropertyItem(20737).Value, 0) != 1;
I have a user-uploaded image pulled from the database that I am resizing smaller to display on a web page that I intend to print. I thought about saving a smaller version when the user uploads it, but since the design of this document hasn't been finalized yet, I was looking for something more dynamic. Also, this document only needs to be printed up once, while the image uploaded is displayed at various places in the app numerous times.
Using javascript to resize it while keeping its proportions, it was printing fine for a while. After adding a margin for styling, the printer started printing the image at its full size. I'm assuming it's the margin. It looks fine on screen but pushes everything off the page on paper.
This led me to look into resizing it on the server, in the C# code, but we use user images uploaded to the database, and I can't seem to find the right time or place in the page life cycle to access and change the width and height. I've tried the various methods on the web using Bitmaps, but they all want a file, when I am using a FileDownloader page as the image url.
Perhaps I'm looking in the wrong place entirely and need to go back to the client. Advice and help is appreciated.
As long as your FileDownloader page returns the proper resized image, it shouldn't matter that you're not point to an actual image.
I'd something like this in your FileDownloader page (pseudo code):
using (Image img = LoadImageFromDatabase())
{
using (Image resized = ResizeImage(img))
{
Response.Clear();
// Set proper headers
using (MemoryStream ms = new MemoryStream())
{
resized.Save(ms); // maybe the function isn't called Save, can't remember a 100%
ms.Seek(0); // Can't remember if this is necessary
Response.BinaryWrite(ms);
}
}
}
Like I mentioned it's highly pseudo code, but it should be straight forward with a Visual Studio open, I just haven't access to it right now, and it's been quite a while since I last used this (since I'm stored the resized images like most other in this question recommends - I do so too, however I realize this is not an option for you)
When you are going to have to resize an image to known constraints, and there's the possibility of having to do that multiple times, I'd always advocate doing the resize once (on upload) and storing the result. Of course, you don't say that you need to retain the original image size, but if you do, then you just have to store the image twice - once original size and once at the resized dimensions.
Once you've done that, you can worry about defining your print layout based on the known dimensions of the resized image, and not have to faff about resizing for each use.
I would suggest converting on upload and possibly saving both images in case you want to let the user click through to the full image. Using this model you only do the conversion once and can render either size image. The GetThumbnailImage() method on the Image class will do what you desire, something like this:
String imageFile = uploadedFileName;
Image baseImage = Image.FromFile(imageFile);
Image thumbImage = baseImage.GetThumbnailImage(300,300,..., ...);
SaveMyImage(baseImage);
SaveMyImage(thumbImage);
Be sure to check the documentation for the parameters to GetThumbnailImage() to verify scaling issues and callback handling.
Could you implement such a process:
User sends an image
Image is opened by a function/routine/script, while the user waits
Image is resized on the fly and saved in the correct location which returns a code for success
User receives a message depending of the return value of the script.
EDIT:
I agree with most of the replies you got here.
If the pictures are stored in a database you need to first make thumbmails for all pictures and put them in the same database, then you need to implement a process to create the thumbmails on the fly when adding new pictures.
Disclaimer: I'm suggesting the open-source library I designed for this purpose. I'm definitely biased, but 4 years and thousands of happy users justify my bias :)
You shouldn't be resizing images inside an .ASPX page, or serving them either. Images should be handled in separate requests by a HttpModule so responsiveness doesn't suffer.
If you have some kind of ID in SQL for each image, you can use the SqlReader VirtualPathProvider to make it accessible via a URL, like /sqlimages/id
Combine that with this free, open-source dynamic image resizing module, and you're set.
You'll simply reference images like this: http://localhost/sqlimages/id?width=300&height=200 from your HTML, and you may not even have to write a line of C#.
If you write your own solution, read these 28 pitfalls you should avoid, so you don't end up crashing the server.
Hope this helps!
I have imported an animated GIF as a resource into a picturebox - unfortunitly it only plays to the end frame and never repeats. Id there something I could do to make it loop continiously. The gif is for my "please wait busy box"
Brad
Animated GIFs have a few different settings. Usually, embedded in the file is some data that tells the renderer how the image should be displayed.
This data says how fast the image is animated, if it should loop infinitely, or how many times it should repeat.
There are several programs available that you can use to edit an animated GIF and change the looping settings.
First, I'd open your GIF in some app to preview it to see if it loops before trying to alter the image.
You can use the System.Drawing.ImageAnimator class helper. You have the Animate, UpdateFrames, and StopAnimate methods to control the loop.