Copy of the screen area - c#

I need to move the black square in an arbitrary area of ​​the screen and copy screen area inside black square to area in my application.
How to do it? Thanks.

Take a look at Graphics.CopyFromScreen():
http://msdn.microsoft.com/en-us/library/system.drawing.graphics.copyfromscreen.aspx
As for the movable black rectangle, I'd suggest making a transparent form and manually painting the border as desired. Use the client area size and position of the form as a hint as what to pass to CopyFromScreen().

Related

How to anchor one empty game object inside stretchable image in unity

I'm setting up a new app UI (Android), there I need to anchor one empty game object inside a stretchable image. I tried all anchor presets, but when mobile screen resolution is changing my stretchable background image stretching according to the screen size. So I can't able to pin that game object on the specific place in the background image. . That Blue image is a movable image I have to stop that image at that red dot(game object).(1080p resolution)above images.
In Above image, you can see that red image went out of its actual position after changing the screen resolution.(Xperia One resolution (1644 * 3840)).
Because of this, I can't able to stop that movable blue screen at a specific position.
Note: Above all images are sorted by layer by layer with some transparent in the middle of the main image. This is for producing water filling effect in 2D.

Specific Draw region within Game Window

Part of the problem I am having with what I am trying to do is trying to explain to others what I want. What I am trying to accomplish is an in-game pop-up menu or window which has its own Draw area. For example lets say I have a pop up window with multiple objects stacked on top of each other, such as button, but there are too many to fit on the window so you need a scroll bar to move them into view. What I want to do is make these object only Draw inside of the window:
http://imgur.com/8IWNEqN
The black area with scribbled pink is the main game window and the centre image is the pop up windows, the dark blue squares being the objects inside. Any code, suggestions, and mainly theory will be appreciated. I've tried drawing them only when they're inside the window and this works but it doesn't look very smooth, I want the object gradually disappearing as they move out the window, not just vanishing when they touch the borders, and especially not slipping out of the window.
Thanks.
Before you do any rendering in XNA you can set the ViewPort on the GraphicsDevice. This lets you restrict where things are being rendered.
For example, if you want to render something to a 100x100 pixel area at the top-left of your screen you might do:
// Create the rectangle
var clipRectangle = new Microsoft.Xna.Framework.Rectangle(0,0,100,100);
// Set the rectangle when you call SpriteBatch.Begin:
mSpriteBatch.Begin(SpriteSortMode.Immediate, renderStates.BlendState,
samplerState,
depthStencilState,
rasterizerState,
null, matrix,
clipRectangle);

How to determine rendered size of graphics in Image Control

I have an Image control set for Uniform stretch. It is wider than tall (landscape). I am putting a graphic (source) in it that is taller than wide (portrait). This means that the top and bottom of the graphic match the top and bottom of the Image control and there is 'dead space' on either side of the graphic. Got the picture? (pun intended)
At this point I zoom in and out of the graphic using a Matrix.ScaleAtPrepend on the Image control and pan using Matrix.OffsetX and OffsetY. Works great.
Now I would like to click on the panned/zoomed graphic and get the pixel coordinates of my click relative to the graphic and not relative to the Image control.
How might I do that?

Create an effect of magnifying glass for a picturebox

I would like to know how to create an effect of a magnifying glass for a picturebox.
Not zooming the picturebox but magnifying a part of the the image in the PictureBox control (circle or rectangle) and setting the size of the glass and the magnification factor.
It may only work within the picturebox control.
Language: C#
Thanks in advance !
Basically, you'd need two pictureboxes. One for the whole image and another for the magnified section. Also, you have to place the magnified picturebox according to user's mouse position.
You'll find a good article about it at http://www.codeproject.com/Articles/21097/PictureBox-Zoom. Just change the source to show the second picturebox in appropriate place (under user's cursor position).
You need 2 picturebox objects, one for picture itself and second for magnified area.
Next load picture into memory, you haven't specified source of the picture but in any case I recommend using streams.
Then create bitmap image in memory.
Using Image method set property of a picturebox.
To create source image for magnifying picturebox you need to clone selected part (calculating dimensions of a new picture area). Whole thing is not as trivial as you may expect as clone method accepts Rectangle objects as an area selector and generally works on rectangles rather than circles to copy selection. I also recommend to Dispose() unused bitmap objects as soon as possible.
Hope this helps.

C# Image over another image

I have a picturebox with a fixed sized image (256x256) generated by the program. I have another smaller image as a resource. What I want to do is when my cursor is over the image and I hold down the mouse button, the smaller image "anchors" with the mouse pointer so it moves around with it. If I let go of the mouse button, the smaller image will stay in that position on top of the bigger image. The smaller image is basically a marker, something like an X or O.
I was thinking of having a second picturebox on top of the first picturebox but I can't make it transparent. Or redrawing the image with the smaller image on top of it and reloading the image into the picturebox, but I'm not sure how to do that and I think it's going to be pretty slow redrawing it each time I move the mouse.
So how can I have a marker image move around on top of a bigger image and have it stay there?
Create your control for this instead of using PictureBox. PictureBox should be used ONLY for fixed images on the form, nothing else.
Instead, derive your control from UserControl. Turn on double buffering for it. In OnPaint method, first draw your background picture, then your marker picture after it. Don't worry, it WON'T be slow and it WILL work as it should.
When you release the mouse, update background picture by drawing your marker picture on it.
Since every sentence here is a little discovery by itself, hope you'll have a good time coding your little game :)

Categories

Resources