For debugging purposes, I'd like to draw on an image in my c# app (I have lots of tiles and I'd like to know which one is which). However, when trying to do it via System.Drawing.Graphics, I run into the fact that the image I'm trying to draw on is a GIF (which I don't have any choice over). Is there another way to draw on images in c#/.NET without using the classes in System.Drawing?
Technically, this isn't the question you asked, but I'm guessing the reason you're not able to draw on the Bitmap from your GIF is that the pixel format is indexed. If so, that's easy to work around by making a copy with a non-indexed format using the Bitmap.Clone method. Just give it the full bitmap size and PixelFormat.Format32bppArgb.
I don't know any other standard drawing API's in .NET that are convenient for this purpose.
Related
I asked another question about generating high quality graphics in a service on Windows Server and SharpDX looks like a reasonable possibility. However I am finding it difficult to find current how-to style documentation. I am specifically interested in the WARP device context.
My use-case is for generation of png format images, and steps of interest are initialisation, loading existing images, drawing graphics and text on them, a resizing / scaling, and saving to png format. I mention this as a large part of the potential use cases for SharpDX are game-related and focus on buffer chains and rendering to forms, which I do not need to do.
This is question 1 then - what is the minimal C# code required to create a drawable 2D surface using WARP in SharpDx in preparation for the above use case.
Other code I have found via Google is either game-focussed, not using WARP, or is simply too complex as it covers more basis.
I'm using the ImageResizer .net library. It works as expected, but one image messes around.
I've uploaded the image below. I've already tried some things like format=jpg&quality=100, only width=220, also different sizes, but it always adds this blurry border around the image.
The original image is a png.
This one is the original image:
This one is resized by the ImageResizer:
And this one is resized with photoshop:
EDIT:
If you're running into the same issue. Try to set up the SpeedOrQuality Plugin. I've set it to speed=3 and the image is sharp again.
Vector graphics require different resampling algorithms than photographs.
ImageResizer V4 includes higher quality image resampling options under the FastScaling plugin.
For graphics (non-photographic images), I suggest playing with &f.sharpen=0..100, &down.preserve=-5..5, and &down.filter=Robidoux. Make sure &fastscale=true and FastScaling is installed.
You can certainly find a good configuration for your rasterized vector art and set up a preset for it. FastScaling is capable of much better resampling than Photoshop - on par with Lightroom, in fact.
Enabling fastscaling alone helps substantially (?width=200&fastscale=true):
Adding sharpening gives a very clear result: (?width=220&fastscale=true&f.sharpen=100):
Visibly crisper than Photoshop:
Each time you save a jpeg, you loose quality (the image is reencoded).
I would recommend using the same quality as the original image was save against, it should give the best results.
Using a higher quality is not recommended as it will artificially try to improve quality, mistaking approximations done by previous encoding for details, resulting in things like the blurry border.
Aside that, usually, one should not use a quality over 95 for jpeg encoding.
I have a .png image that's just white-on-transparent, and I'm wondering if there's an easy way to make that green-on-transparent, red-on-transparent, etc so I don't need to make separate .png files for each color.
Take a look at these CodeProject Articles
Image Processing Lab
ImageMagic-WPF Image Color Spaces
Image Processing Lab is a simple tool for image processing, which
includes different filters and tools to analyze images available in
the AForge.NET framework.
You could also take a look at the FormatConvertedBitmap, ColorConvertedBitmap or WritableBitmap Class's
For a simpler solution that doesn't require pulling in huge libraries and lets you understand what's going on under their hood (and thus gives you greater flexibility), learn how to use WPF Pixel Shaders (google it).
Then you can use something like the multiply shader here: http://rakeshravuri.blogspot.com/2008/08/blending-modes-in-wpf-using.html
I want to use some of these bitmaps on the MS Office Ribbon control, basically like:
ribbon:RibbonButton x:Name="btnCollapsed" SmallImageSource="Images\Collapsed.bmp"
The following is from:
VS2010ImageLibrary\Objects\bmp_format\Office and VS_MSObjects_24bitColor_bmp_OfficeVS - Readme.html
"Visual Studio Image Library: Objects (24-Bit, .bmp Format, Office and Visual Studio style)
24-Bit Art
This art is 24-bit color. Transparency should be achieved by mapping RGB:255,0,255 to the background color of the UI."
I am trying to use the VS 2010 Image Editor but can't figure out what I need to do. I am guessing I need to save the bmp as PNG but what else? I could manually change the RGB:255,0,255 of each bitmap I need to the pale blue background of the ribbon but I think there should be a simpler technique (e.g., like specifying what the transparent color is)
Any help greatly appreciated.
That's Color.Fuchsia. It's a great fuchsed-up color that is very unlikely to ever be used in a bitmap. Very commonly used in old C/C++ user interface code to make 24-bpp bitmaps, a format that doesn't support transparency, into bitmaps that behave like they do. I'll spare you the C code that's required to make that work, it's quite fuchsed-up.
A lot of the bitmaps that are in the image library came from internal Microsoft projects that used this trick. Big chunks of Windows are still native C++ code that uses the raw Win32 api, GDI doesn't support transparency at all so 24-bpp was common.
You'd need a decent graphics editor, the first order of business is to turn it into a 32-bpp bitmap. Then color-replace. I'd personally use a quicky .NET program that uses Bitmap.MakeTransparent(), draw to a 32-bpp bitmap and save that as a .png
You need to convert the images to PNG with proper alpha transparency as WPF does not provide color key transparency functions without resorting to WritableBitmaps or custom BitmapSources.
This application can convert your bmps to proper transparent PNGs by selecting the Magenta color key: http://transparentpng.codeplex.com/releases/view/54303
I have a .NET GDI+ bitmap object (or if it makes the problem easier a WPF bitmap object) and what I want to to is shift the whole lot by dx,dy (whole pixels) and I would ideally like to do it using .NET but API calls are ok.
It has to be efficient bacause its going to be called 10,000 times say with moderately large bitmaps.
I have implemented a solution using DrawImage - but its slow and it halts the application for minutes while the GC cleans up the temp objects that have been used.
I have also started to work on a version using ScrollDC but so far have had no luck getting it to work on the DC of the bitmap (I can make it work buy creating an API bitmap with bitmap handle, then creating a compatible DC asnd calling ScrollDC but then I have to put it back into the bitmap object).
There has to be an "inplace" way of shifting a bitmap.
mikej
Have you found the Graphics.FromImage method? That will let you manipulate the bitmap directly. I'm not sure what you're using with DrawImage, but Graphics.DrawImage should let you copy an area of the bitmap onto itself (and apply a shift in the process).
Alternatively, given a Graphics object, you can use Graphics.GetHdc, ScrollDC and Graphics.ReleaseHdc.
Do you just want to move the whole graphic? DrawImage has x,y parameters to do that. I'm probably not interpreting your question correctly.
As an aside, GDI is not going to be efficient period when you're working with 10,000 images. If you want anywhere near real-time performance you're going to have to either rework your algorithm or look into a 3D API (like DirectX or OpenGL) or possibly both.
Sorry if my question wasn't too clear.
All I'm trying to do is in place scroll a bitmap i.e. do a shift operation.
For example, a method like Scroll(B,1,0) would shift the entire bitmap B one pixel to the right.
I've got reasonable solution using both DrawImage and the ScrollWindowEx API call which is about 10 time faster.
I'm still trying to work out how I could do something faster using WPF.
I've written up my solution to the problem at Scrolling a bitmap but I'm still not sure that there isn't a better way and if it might be better done in say WPF?