change the color of the clicked pixel - windows-phone

I am writing a Windows Phone 8.1 app. There is a rectangle object in my app and in the Rectangle, I want to change the color of the pixel where user clicks. I have retrieved the pixel coordinates using the PointerPressed event of the rectangle(I retrieved the relative coordinates). My question is what function/method of the rectangle should I use to access the pixel properties so that I can change its color? Thanks

You can do any of the 2 things.
Use Canvas instead of the Rectangle, in click handler create some shape object (e.g. ellipse or path), add that element to the Canvas' children, specifying correct position with Canvas.SetTop / Canvas.SetLeft static methods.
Fill your rectangle with an ImageBrush constructed from a WriteableBitmap, write pixel values in the WriteableBitmap.
If your user will only paint a few pixels, Canvas + shapes approach is more efficient. If you expect your user will paint many pixels, WriteableBitmap is better.
P.S. Don't forget there're devices out there with 1080×1920 px screens, such as Nokia Lumia Icon, Lumia 930, Lumia 1520, Samsung ATIV SE. Individual pixels will be invisible on those devices.

Related

Draw rectangle on image in Avalonia

Problem : I have an image with zoom and pan attached. I need to draw rectangles over it.
What I have done : I created a Canvas as an overlay over the image and made rectangle the children of canvas. Everything works well with zoom and pan etc but if the user resizes my the window then the added rectangles starts moving from their places because the rectangle position is set with respect to top and left of canvas.
I am thinking of drawing rectangles over the image and overriding the render. Any suggestions how can I achieve it easily?

Multiple Stages on Same screen with different viewport LIBGDX

I am trying to scale my application to work similar on various aspect ratios.
I read about viewport and camera. And came to a conclusion that I should use FitViewport for my game stage so that no asset is being stretched. And I will use some background image to fill the black bars caused by fitviewport. But the problem is, whenever I use any other viewport than FitViewport for background image, the whole stage (both background and main stage) are being stretched, is there a way we can get away from black/white bar of FitViewport? I tried all the viewports for background namely StretchViewport, ScreenViewport, FillViewport.
Am I missing something very trivial? or is setting up multiple different viewport on same screen possible.
ps I was able to setup two same viewports with different size on same screen.
Here is the screen, I am getting after fitviewport. Notice the white bars on top and bottom which I am trying to eliminate.
this answer worked for me. Just for reference
You would need a second viewport, probably ExtendViewport with the
same virtual dimensions as your FitViewport.
//create:
fitViewport = new FitViewport(VIRTUAL_WIDTH, VIRTUAL_HEIGHT);
extendViewport = new ExtendViewport(VIRTUAL_WIDTH, VIRTUAL_HEIGHT);
//resize:
fitViewport.update(width, height);
extendViewport.update(width, height);
//render:
fitViewport.apply();
batch.setProjectionMatrix(fitViewport.getCamera().combined);
batch.begin();
//draw game
batch.end();
extendViewport.apply();
batch.setProjectionMatrix(extendViewport.getCamera().combined);
batch.begin();
//draw stuff in border
batch.end();
If you want to be sure the border stuff doesn't overlap your game, you
could swap the draw order above.
Or you could just use ExtendViewport to begin with for everything.

Draw with mouse and save the drawn region as separate image

Please see following picture:
background picture
The image Abc in red color is the background picture, maybe preloaded on some control, for example a picturebox control.
The black rectangle region is drawn using mouse. What I want to achieve is to copy out the drawn region as separate image.
My goal is the winform will display each mouse drawing stroke until there is a closed region being formed or enclosed. That means a closing contact point need to be tracked.
Could you advise me on the key classes that I need to look into?

Circular images

In my application, users are allowed to choose a picture they want and this picture shows up in a picturebox.
I want to know if there was a way so that this picture that they select becomes circular instead of a square?
I want all images they select to be circle shaped.
Is there anyway to do this? Doesn't even have to be a picturebox control, anything that can accomplish this is fine
I tried this with no luck - http://www.codeproject.com/Questions/430531/circle-shaped-picture-box
Not the smartest way, but worked for me in similar task. If your picturebox is fixed size, you can create "mask" which will hide the corners.
Just draw an image in PNG with transparent circle in the middle and make the rest same color as your form. Use this image as Image propperty of each imagebox and set your image as "backgroundImage" property. This way, the image will look circle-shaped.
If you need imageboxes of different size, you can create the circle mask programmatically.
EDIT: If you will prepare a calculation of circle, you can also use it to "crop" the images to circle shape. It all depends on what you want to do with these images later.
Do you need to use them later in circle or rectangle shape?

Xna scroll-able view

How do I make a scroll-able map. For example, my preferred back buffer is 800x600 and the map is 2400x1800 (approximately 3x3). Also, how do I handle the keyboard state to scroll and do walking. I know most games keep the player centered and scroll the world. The problem with this approach is the corners. There would be a large unmoveable area.
To make scrollable map you can use simple Rectangle or ViewPort (named camera):
' Initialize camera with size of game viewport
Dim viewport As Viewport = spriteBatch.GraphicsDevice.Viewport
Dim camera As New Rectangle(viewport.X, viewport.Y, viewport.Width, viewport.Height)
' Draw method code
spriteBatch.Begin()
spriteBatch.Draw(image,
New Rectangle(0, 0, viewport.Width, viewport.Height), // Destination rectangle
camera, // Source rectangle
Color.White)
spriteBatch.End()
By changing camera.X and camera.Y values you can adjust origin from where your image is drawn thus moving camera around. For example following code would move your camera to the right:
Dim keyboardState As KeyboardState = Keyboard.GetState()
If keyboardState.IsKeyDown(Keys.Right) Then
camera.X += 1
End If
Walking can be done very similarly, by increasing character position X and Y coordinates when according buttons are pressed.
Keeping player in the center of the screen is a bit trickier. Basically you want to keep character in the center of the screen at all times except when distance between it and edge of world is less then half the screen. In this case stop moving camera and start moving character off of center to the desired side.