Unity making a button to take two screenshots - c#

I want to make a screenshot basically "OnRender" because I'm making the screenshot via a button that I want to disappear before the screenshot is taken and reappear afterwards.
Here's the code for the screenshot: https://hastebin.com/ecirojupov.csharp
And this is the function the button calls:
public void screenshot()
{
screenshotButton.SetActive(false);
Screenshot.TakeScreenshot_Static(Screen.width, Screen.height);
screenshotButton.SetActive(true);
}
But using either OnPre or OnPost Render doesn't work. While using OnRender leads to Unity telling me that "No cameras rendering". (In "telling" I mean text appearing in the middle of my screen) Once that message appears I can also not interact with anything anymore.
How can I take this screenshot while disabling the button?

Related

Scale button to text Xamarin Forms

Is there a way to scale a button to it's text or align the text left?
I have created a static method that allows me to set a generic theme for my buttons. I know you can use LayoutOptions.Start to make the button go to the left of the page.
public static void DefaultButtonTheme(Button button)
{
//previous code
.
.
button.HorizontalOptions = LayoutOptions.Start;
}
However, for text smaller than a certain amount of letters it is center of the button.
See image below.
I have investigated a bit this behaviour and I have found that this error appears on Android but not on UWP. I have also tried to use MinimumWidthRequest="0" without result.
So as Anto Maniscalco said you should create a custom control and then overwrite the Android render using android:minHeight="0dp" as you can see in the following link. It seems that Google decided by default to a minimum size for this control.
I hope this can help you.

MonoGame - Working With Specific Gestures for Different Purposes

Part of my particular dilemma is that I would like to be able to get the initial position of a drag gesture. Depending on the initial position of that drag gesture, the application would either 1) pan the view or 2) display a menu, but not perform these gestures at the same time (which is where part of struggle lies).
For example, if the user initiated a drag from the very left side of their screen and dragged inwards, a menu would pop in instead of the view panning.
I would also like to be able to execute a double tap gesture without also activating a tap gesture, if that's at all possible. I've tried working with boolean flags - for example,
// ...
if (gesture.GestureType == GestureType.DoubleTap)
{
isDoubleTap == true;
}
// ...
public static Vector2 Tap
{
get
{
if (!isDoubleTap)
return gesture.Position;
// ...
But that doesn't work.
I've tried using TouchCollection - if anyone would like me to elaborate on my issues with that I can, but for now I'll say what I tried hasn't worked. It's entirely possible I may have just goofed as I am a novice when it comes to working with touch input.
I've been working on this for a few days and have done as much searching as I can, and nothing I've found has alleviated my issue - if I happened to have missed something, I apologize.
Thank you for your time!
Concerning start position of a drag:
There is a gesture for a drag ending, so if you receive a drag and its the first one since the last drag ended, thats the initial position.
Concerning tap/doubletap:
MonoGame works the same way as XNA as documented here:
The user tapped the screen twice in quick succession. This
always is preceded by a Tap gesture.
This sounds like a input-bindings design problem more than a technical question imo. Consider also what you can move to instead occur on press or release rather than only making use of gestures.

Stop preview after photo is taken

My app is supposed to take a photo, then stop there showing the photo, save it in a file and move on to another view.
I use the Microsoft.Devices.PhotoCamera and wait after a photo is taken for CaptureCompleted to take the image and for CaptureImageAvailable to store it and then move on.
Whan happens is: After a picture is taken, I get the camera preview again, which might be confusing for users (though a progress-bar is shown to tell them "wait pls". still not nice) and after 1-2 seconds it shows the taken picture again and moves on to the next view.
Is there a nice way to disable this preview-thing?
If I dispose the PhotoCamera after the first event, it hangs. If I dispose it after the 2nd event, it doesn't seem to make much difference..
Edit:
private void Cam_CaptureImageAvailable(object sender, Microsoft.Devices.ContentReadyEventArgs e)
{
this.imageStream = e.ImageStream;
Deployment.Current.Dispatcher.BeginInvoke(delegate
{
this.image = new BitmapImage();
this.image.SetSource(this.imageStream);
this.PreviewImage.Source = this.image;
// Part where I store the image into a file.
// Part where I navigate to the next view.
});
}
I need that Dispatcher-Thing because setting images and navigating needs the UI-thread but the method runs in a different one.
Also a strange point: it doesn't matter that the PreviewImage lies OVER the canvas with the camera-preview. It is still overwritten as soon as the picture is taken and being processed... ôo
The problem might be that I do many things and the UI is never refreshed. I could add a small sleep (1-5ms) but that would be async again. Also I can't do this completely serparated because the storing part makes a "screenshot" which should contain the final image instead of the camera-preview-thing.
Edit2:
I see the main problem in the capture itself. It takes a picture, shows it for a while, then switches to the camera preview and then back to my shown picture.

Panel is flickering when switching from one winform to another

I render my image on the panel.
using Microsoft.DirectX.Direct3D;
Device device;
this.device = new Device(0, DeviceType.Hardware, this.panel2,
CreateFlags.HardwareVertexProcessing, presentationParameters);
As a result, the panel is flickering when I try to switch the winform from one to another.
I know it is hard to describe the scenario. Hence I hereby upload a video clip (.swf) to my google drive, you guys may download it and open it with window media player to watch the video.
Below is the shared link:
https://drive.google.com/file/d/0B6wTfkJvzke_aVJwanVkaU1iSVU/edit?usp=sharing
Inside the video, I am running my application at debug mode, then I click on the 'chrome browser' tab in task bar to access the 'chrome browser', when the minimized 'chrome browser' pop out, the panel will be flickered. Then when I minimize the 'chrome browser' again, the panel flickered again.
The problem occur when there is some other winform being placed above the panel on screen.
Any comment on the above matter? Help is needed.
I ran into the same flicker issues when using DirectX with Panel. It turned out that the OS draw events were colliding my own. To fix this, you need to disable OS drawing on your Panel by creating a custom panel. Something as simple as this should suffice.
class Direct3DPanel : Panel
{
public Direct3DPanel()
{
this.SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
}
}
The SetStyle method call tells the OS that only you should draw in Direct3DPanel. Note that once you do this, you will be responsible for all drawing. You may need to handle the Paint event and call your draw logic depending on your current architecture.
You can get more information about the different ControlStyles here
http://msdn.microsoft.com/en-us/library/system.windows.forms.controlstyles(v=vs.110).aspx

Remove jquery script from a control

I am coding a galery in jquery.
I have an image zoom tool that is put on a main image on an image_preload event.
I have smaller images that when clicked swaps the main image out with the one that is clicked. The new image is now the main image.
The problem is that the zoom tool is still picking up the old image even though in firebug it says that the new image was loaded into the zoomer.
I want to remove the code that i have on the main image when the switch is made and then put it back on. I'm thinking this will update the zoomer.
i have
$('.MYCLASS').jqzoom();
so can i do something like
$('.MYCLASS').jqzoom().Remove();
Thanks any help is appreciated
You would have to know what the function does in order to reverse its effects. It might be that the plugin provides a remove function, but I doubt that it would work in your instance.
One suggestion might be to simply clone the $('.MYCLASS') element and delete the original which has been bound with the jqzoom() plugin.

Categories