How to work with pixels in WP7 Silverlight? - silverlight

I have an image, I want to get a pixel color, replace a pixel color with another, and other operations on pixels.
Is there a way to do that? And what libraries are needed?

Have a look at the WriteableBitmapEx library. This will allow you to manipulate pixels directly.

Related

how to scale an image with gimp and save the actual scale and all the white space

there are a ton of scaling instructions for GIMP but all of them tell you to scale and save easy peasy. I feel like I'm taking crazy pills.
This is what my save or export generates:
How can I simply export a selection? Shouldn't the GIMP instructions include this detail? Sorry for ranting.
In Gimp (and some other popular image editors) the image you work on is actually made of separate images (a.ka.a layers) held together on a "canvas". The "canvas" gives the size of the final image.
There are three different ways to scale things and you have to use the right one:
The Scale tool : scales the active layer by dragging corners. Doesn't change the size of the canvas. This is probably what you used.
Layer>Scale layer: scales the active layer by providing explicit dimensions. Doesn't change the size of the canvas.
Image>Scale image: scales the whole image contents and the canvas. This is probably what you should have used.
What happened to give you the image above is that you resized the layer using the Scale tool, so you got a tiny image in the corner of the canvas, which didn't change size. The uncovered part of the canvas was displayed as a checkerboard pattern. If you exported to a format that supports transparency such as PNG or GIF the image would have been transparent, but since you exported to JPG which doesn't support transparent images Gimp replaced the transparent part by the default background color.
Everything is well explained on their website. https://www.gimp.org/tutorials/GIMP_Quickies/

Bit blit Bitmaps (WriteableBitmapEx Framework)

I've not fully understand the basics of Bit blit bitmaps.
I'm using the WriteableBitmapEx framework (WPF). My bitmap represents a map and what I wanna achieve is to copy a (moving) symbol into that map.
For actual copying, I use the function Blit:
_bitmap.Blit(myObject.Value.Location.ToWindowsPoint(), symbol, rect, Colors.Cyan,
WriteableBitmapExtensions.BlendMode.Additive);
where symbol is a png image(transparent background).
This works in prinicpal but I do not understand how the color (Colors.Cyan) is applied by the blend mode. I've tried out all available blend modes but I've not succeeded in getting Cyan as the color of the symbol or I got the color but then the transparent background was also copied to the source bitmap (black background).
Is 'Bliting' the wrong approach for my use case?
Thanks.
A much easier approach is to use images (corresponding WPF ui element) and layer it above the bitmap. This has also the advantage that you can move the image without redrawing the bitmap at all.

silverlight image control brightness and contrast

Does anyone know how to apply brightness and contrast control to an Image in silverlight 5? Maybe using UIElement.Effect? I don't need to modify/save the image, just change how it is displayed.
Use a WriteableBitmap as source for your image and then apply a brightness/contrast formula on every pixel of the WriteableBitmap.
You need to call Invalidate() on your bitmap instance after you have changed the pixels.
I ended up using a Custom Pixel Shader. Shazzam has a contrast adjust custom pixel shader in it's pre-installed samples. The beauty of this is that it works in both WPF and silverlight.

WPF Image, changing color of pixels

I have a problem. I need to fill (or repaint) some pixels at image, stored in Image control. This is a png image. I mean, that all black pixels should be filled with, for example, red color. How can I do this? I thought I can access directly to pixels and using XOR change special bits, but I don't know how to do this. Or maybe there is an easier way?
The GetPixel and SetPixel methods should work for what you need.
This answer has a code sample that you should be able to adopt for your use.

Generate Texture in Silverlight imitate leather

I would like to display textures in different colors pretty much having this texture.
How do I do this in Silverlight?
Thanks!
alt text http://a.imageshack.us/img535/5255/leathertexture.png
Turn your texture into alpha textue. Exact steps will depend on your image manipulation software. After that simply place your texture on top of colored rectangle.
You could make pixel shader for even better result, but that would be an overkill in your case.

Resources