Cannot make watermark image for Signature - c#

I have a logo image that I need to embed in the signature. The logo is such like, a square with 4 parts & each of different part. I want to set watermark on the image, so the text is visible clearly. The code that I use is :
sap.Image = logoSign;
sap.ImageScale = 0.40f;
sap.Image.SetAbsolutePosition(100, 100);
//sap.Image.Transparency.SetValue(50, 0); // Only half image is visible
sap.GetAppearance().AddImage(logoSign);
It is scaled & placed properly. To achieve watermark effect, I add Transparency. When I made its value as (30,0) top left part of the square logo was visible. On making it 50, left half is visible, then I tried with 80, 100, 120, but the full logo is never visible. Elther 1/4th or 1/2 is only visible. The right part that is not showing up has Pink & yellow shades. Surprising is, when I comment the Transparency line, whole logo is visible.
Can anyone help me know, why is it acting like this. And ya, the logo with GIF is only working. PNG &/or JPG logo doesn't show up. Why so ?? I tried other image of jpg also, but no success.
#mkl, RESULTS shown in screenshots
Thanks

My advice would be to edit the image itself to a particular transparency level with the help of an editor and then use it. why do it in the code.

Related

Image not displayed correctly when moved

I have an image <Image x:Name="image" Source="fingerprint.png" Height="1000"/>.
The image is higher than the form, so it doesn't fit in it completely.
When I move the image by image.Margin = new Thickness(0, image.Margin.Top - 50, 0, image.Margin.Bottom + 50);, the part of the image that wasn't visible before is still not visible, although it's now in the form (see red arrow).
Putting the image in a canvas solved the problem.
The Margin of the image will only control how close to the edges of the parent control your image is allowed to be.
I'm not sure what you are trying to achieve, but if you want the bottom of your image to be visible you need to either change its Position or scale it to fit inside the parent control.
Check this http://www.wpftutorial.net/LayoutProperties.html link to see some visualizations of layouting in WPF.
http://wpf.2000things.com/2011/04/14/276-change-image-sizing-using-the-stretch-property/ has some explanations about how to scale an image.

Overlay of two images - Control which part is in the foreground with mouse coursor

I need to be able to compare two different Images in the following way:
The images are displayed on top of each other so first there is only one image visible. When hovering with the mouse coursor over the image this defines the X-position of a vertical line which is splitting the image, displaying part of the first image left to the line and the rest of the second image right to the line.
This basically should be used as a quality comparison for two images with identical contents.
Here is a picture that hopefully makes my intentions clear:
you can use splitter control. splitter one side you put one picture control another side put other picture control
I was able to resolve this by using a SplitContainer and custom drawing. As described in the comment of Vasanthakumar's answer purely using a picturebox is not enough as you will not be able to align the right image at the same starting point than the left image (top left of the form).
What I did was the following:
pictureBox 1 displays its image normally
the Image in pictureBox 2 is drawn on every move of the splitter (this.splitContainer1.SplitterMoved += new System.Windows.Forms.SplitterEventHandler(this.splitContainer1_SplitterMoved); with a custom subset of the Image to be displayed.
This effectively allows to generate the overlay I need.
Part of my implementation showing the drawing logic:
Bitmap bmp = new Bitmap(gImg2.Width, gImg2.Height);
using (Graphics g = Graphics.FromImage(bmp))
{
g.DrawImage(gImg2, 0, 0, new Rectangle(e.SplitX, 0, gImg2.Width - e.SplitX, gImg2.Height), GraphicsUnit.Pixel);
}
pictureBox2.Image = bmp;

C# TextRenderer text black shadows

I have a project the put random quotes on desktop wallpapers, you can position them, top or bottom. Anyhow, the text works great when using DrawText, but since it is required to have a custom alignment, LEFT, CENTER, or RIGHT.. I moved to using TextRenderer.
below is the screen shot, and if you notice, there is a transparent horizontal box along the screen with text.
but since Stackoverflow is crashing everytime I upload a HiRes image, I just resized it and just show this to you
notice the black shadows around the characters? How do I get rid of that?
-----------------
solved by adding
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

Weird glitch with ASP.net drawing

I have a code that draws a few things. At the end, it draws a string. The string looks like it was copied from a text editor -- really nice! But weirdly, when I try to draw exactly same image only 10 pixels wider, the text gets blurry. When I say wider, I only mean like initializing a Bitmap with +10px width. Image still draws on the same area like those 10px were not there.
I already checked measureString. It seems fine. My first thought was that it measures wrong and shrink text width but that can't be case since I'm only passing text and font to measureString.
I already tried drawing the text then copying the whole Image to a new Bitmap only 10px wider (Image again stays the same width, the 10px are just blank space) but exactly same thing happens. I have way too much code to post it all. Any suggestions as to what could be the problem?
Example:
Thanks
You most probably forgot about a late-on width constraint which is keeping your final picture from expanding in width correctly: in your "resized" sample the drawn text is being shrunk, so logic (and the proportionally wider whitespace to the right of the "resized" sample) suggests you're actually trying to fit a wider picture in the same area.

How can I set an image to have a transparent background in C# without using Bitmap.MakeTransparent()?

I want to set an image to have a transparent background, but I do not want to replace all pixels of a specific colour with transparency.
To be more specific, the image is a thumbnail image for a folder, obtained via IShellItemImageFactory.GetImage. This gives me a Bitmap, as displayed in Windows Explorer thumbnail view, but the background is solid white.
I can use Bitmap.MakeTransparent on it, and that will work in most cases, but in any cases where the thumbnail image contains white itself (for example, a folder that contains images, which include white colours).
Incidently, this is the first time in over 10 years as a developer that, after googling my question, I have not found an answer anywhere, and I've actually had to ask it myself. (I think that means I just levelled up! Yippee, I am now a level 2 developer...)
Use flood-fill algorithm to fill pixels of the same color from the OUTSIDE as you need it. It is something similar to magic wand in photoshop.
http://en.wikipedia.org/wiki/Flood_fill
What I would do is flood-fill with some obscure color (Magenta always does it for me), then replace that color with transparent (I don't know if flood filling with transparent pixels is feasible).
So what you're getting from IShellItemImageFactory.GetImage is a composite image that contains the original image on a white background? I suspect the white background is there if the image doesn't have the same aspect ratio as the thumbnail size. For example, if you ask for a 96x96 thumbnail of a 640x480 image, there's going to be some white space at top and bottom.
If that's the case, you have a problem. You can't differentiate between white pixels that are contained in the image, and white pixels that are added by GetImage.
There are a few things you could do. You could load the image and resize it yourself. That's probably the easiest. You'd want to maintain your own thumbnail cache then.
Or you could examine the image returned by GetImage to look for white space on the sides. Basically, if every pixel on a row (or column) is white, then make that row (or column) transparent. It's a little more complicated than that (the NBA logo, for example). But that's essentially what you'd want to do.

Categories