Alpha channel not working - c#

So I am writing a basic app for the windows phone but the alpha channel doesn't seem to be showing up in any of the images I use. In Fireworks I can see the alpha channel in there.
<Image Source="Assets/Images/OnBar.png" Width="100" Height="60" Margin="280, -560, 0, 0" />
That is the xaml code used to display the image in the first place. Currently I don't have any C# code behind it so if I need to implement something on that side a point to the right direction would be appreciated. I looked around but couldn't find anything that worked or was useful. The Image itself is also white so if the alpha channel doesn't work then nothing will display. Any help is appreciated.

Just tested it, it works fine with an arbitrary transparent Image. Maybe your png export format isn't compatible with xaml. Or your Imageis inside a container which isn't transparent.
But you don't forget to declare anything in Image's parameters, alpha channel is built-in and no tweakable, as far as I know.
Please provide more details and I'll edit my post.

Related

How to create custom shaped Buttons in WPF?

(Before this gets marked as a duplicate, I'd like to say that I've tried the answers on other posts, but they don't seem to work for my specific issue.)
I'm creating a sort of "map game", where there's a map split into multiple areas. Currently, this is what I have:
It works, but it's not pretty. I want to make the buttons (currently they're the Rectangle control, but I can change that easily) the right shape.
I tried making a path in Inkscape, which gave me this SVG path:
m 283.60033,267.22114 11.61675,32.57742 14.14214,-8.33376 10.35406,-1.01015 11.61676,-5.3033 10.6066,-5.05077 0,-16.66751 -34.85027,-3.78808 -8.08122,2.77792 -14.64721,0.75762 z
However, when I tried to make a Button (and later Polygon) use the path, it didn't work and instead made a completely different shape.
The Buttons need to have a background color that can change during runtime, so a PictureBox won't work.
Is there a reason why the Path didn't work? Or maybe there is a much easier method?
EDIT: Here is the code I used for the Polygon
<Polygon Fill="Blue" Points="283.60033,267.22114 11.61675,32.57742 14.14214,-8.33376 10.35406,-1.01015 11.61676,-5.3033 10.6066,-5.05077 0,-16.66751 -34.85027,-3.78808 -8.08122,2.77792 -14.64721,0.75762" Margin="248,102,956,22" RenderTransformOrigin="0.5,0.5" Grid.ColumnSpan="2"/>
And here is the result, which is the same shape I got when I tried changing the shape of a Button (unfortunately I deleted the code for that):
Here is what it should look like (path drawn in Inkscape):
I figured it out and it was actually pretty easy! I actually didn't need Inkscape at all.
I imported the map image into Blend, and I traced the area with the Pen tool and made it into a Path, which I copied back into Visual Studio.
Example:
Are you sure you didn't get mixed up with which part you picked out the xaml inkscape produced?
Because that's roughly the top right part of the iberian peninsular. Like your drawn map. Roughly anyhow. That's just a polygon - with hard edges. Meaning however you produced it, you didn't trace the curvy/rough edges of what you're showing us.
Also.
If you look at the data that's in it.
See where it starts?
m 283.60033,267.22114
Those are x,y co-ordinates.
268px left, 267px down
From the top left corner of whatever container you put it in.
Is that going to work for you?

What type of image filtering/processing do mobile PDF scanners use to convert a captured image into a monochrome/black and white image?

I am trying to implement my own monochrome/black and white filter in C# to scan text documents. My approach is to apply a threshold filter on the captured image. However, I often run into the problem that the varying brightness on the image causes a ''shadowing effect'' on the processed image. Refer to the link below (it is pretty blurry but it should suffice). The image to the far left is the original image. When I apply my threshold filter, I get the same result as the image in the middle; some of the text becomes unreadable because the brightness of the image varies, so some portions become really black or really white. However, with the right filter, you can obtain the processed image to the right where everything looks crystal clear.
https://www.google.dk/search?q=monochrome+image+processing&espv=2&biw=1706&bih=859&source=lnms&tbm=isch&sa=X&ved=0ahUKEwir8vXlhIzPAhUFiywKHeSBC1wQ_AUIBigB#imgrc=4UTzoIpyqTkwrM%3A
I would like to know what the process is to obtain the image to the far right. Another example can be seen in the image below. It shows a sample mobile PDF scanner in use. Scanning the image results in a very nice black and white image, where the text can be easily read and no ''shadowing'' occurs on the image. Does anyone know what this process is or what it is called? It is very often used in mobile PDF scanning applications. Thank you in advance.
EDIT: The filter is called ''Adaptive Thresholding''. You can use the BradleyLocalThresholding class to implement the filter, or you can write it yourself (which is what I did). Please refer to my response to the comment by Yves Daoust down below.
You need two ingredients.
One is "background reconstruction", i.e. retrieving the intensity of the white sheet "under the characters", for instance by morphological opening.
The other is "shading correction", i.e. compensating the unevenness of the background illumination by comparing to the reconstructed background, for instance by subtraction.
This will "flatten" the image, making it perfectly amenable to global thresholding.
A simple method is to convert the image to grayscale and then convert it to B/W using an error diffusion algorithm such as Floyd–Steinberg dithering.

Image rescale (downsize) with Silverlight

I have an array of graphs, that are 2000x1000 pixels pngs. When I put them into a silverlight Image that auto-sized with the browser window, DisplayImage.Source = new BitmapImage(GetHeatmapURL()); they images look distorted and for some browser sizes much worse than for some others.
I want to fiddle with some setting that would improve the quality of this downsampling, is this possible? Am I doing something wrong? My first approach was to put the Image into a Viewbox. That looked even worse. Googling gives virtually nothing useful...
Any help much appreciated.
PS. I'm working with Silverlight 4.
You could check out the WriteableBitmapEx project on CodePlex which gives you a Resize() extension method for the Silverlight WritableBitmap class where you can use either Bilinear or Nearest Neighbor interpolation. Resizing with the Bilinear interpolation might give you something that looks better than the ViewBox resizing, but you would have to test it out.
var resized = writeableBmp.Resize(200, 300, WriteableBitmapExtensions.Interpolation.Bilinear);
When making use of the Viewbox you need to make sure to set Stretch to Uniform to respect the original height/width ratio.
In regards to the rendering of the image at the given aspect ratio and size; that is contingent on the framework.

wpf custom control: audiowaveform rectangle with selection slider

I'm working on a c# wpf app in which I want to do something with audio. the irrklang audio library provides me with a pcm decoded 16 bit byte array.
I want to create a timeline control which shows the waveform along the timeline with an overlaying rectangle which the user can drag and click/drag the left and right side to increase or decrease the selection.
It is used to the trim the audio track. I would like the selected min and max to be databindable, the minimum and maximum value of the total track to be bindable.
To clarify here is an image mockup:
I'm not asking for a complete control but tips and suggestions on how to tackle this are more than welcome. Perhaps solutions like this already exist but so far I haven't been able to find it.
I think I need to tackle: the control (zooming, panning and changing the selection) and drawing the waveform in the control
Thanks in advance,
I think you should check out this codeplex project
http://wpfsvl.codeplex.com/
Refer to Audio WaveForm Drawing Using WPF.
Something based upon WaveFileTrimmerControl.xaml would be useful, it uses related controls PolygonWaveFormControl.xaml & RangeSelectionControl.xaml (links are to the XAML but refer to the CS also). In any case it'd be a good starting point for building a control that exactly meets what you want.
You could override the render method and use primitives which will give possibly better performance; but like anything related to performance I'd try the above approach first which is almost certainly good enough.

Remove image solid background with c sharp

I'm trying to find some info about removing an image background "automagically" if possible in .NET.
Actually I could not find much data and I don't event know if it's possible or are there any API components available.
Any ideas?
Establish a rule, for example that the pixel at [0,0] must be the 'transparent' color (the background). Load the image as a Bitmap (let's call it bmp), and then do something like this:
bmp.MakeTransparent(bmp.GetPixel(0, 0));
Homer, for the file formats you suggest, there is no easy way of defining what the 'background' is. For instance, say you have some colorful text on a white background. I'm assuming you'd want to make the white transparent? There is nothing in the file format to say "this layer or color is the background". There may be heuristics for trying to determine the background color, but there will probably be no library to do something like image.MakeBGTransparent().

Categories