Bmp to jpg/png in C#

var qualityEncoder = Encoder.Quality; var quality = (long)<desired quality>; var ratio = new EncoderParameter(qualityEncoder, quality ); var codecParams = new EncoderParameters(1); codecParams.Param[0] = ratio; var jpegCodecInfo = <one of the codec infos from ImageCodecInfo.GetImageEncoders() with mime type = “image/jpeg”>; bmp.Save(fileName, jpegCodecInfo, codecParams); // Save to JPG

How to cartoon-ify an image programmatically?

Here’s some algorithms to play with: Median or repeated box blur filter to obtain cartoonish color palette Edit: Bilateral filtering should suit your needs even better Min filter (zeroth percentile) to enhance some types of edges Color image segmentation using either small subcube or sphere in the RGB color cube Generic edge enhancement on segmented … Read more

OpenCV: how to rotate IplImage?

If you use OpenCV > 2.0 it is as easy as using namespace cv; Mat rotateImage(const Mat& source, double angle) { Point2f src_center(source.cols/2.0F, source.rows/2.0F); Mat rot_mat = getRotationMatrix2D(src_center, angle, 1.0); Mat dst; warpAffine(source, dst, rot_mat, source.size()); return dst; } Note: angle is in degrees, not radians. See the C++ interface documentation for more details and … Read more

Javascript Image Resize

To modify an image proportionally, simply only alter one of the width/height css properties, leave the other set to auto. image.style.width=”50%” image.style.height=”auto” This will ensure that its aspect ratio remains the same. Bear in mind that browsers tend to suck at resizing images nicely – you’ll probably find that your resized image looks horrible.

Flood fill using a stack

You can use Queue to remove recursion from floodfill algorithm. Here are some basic ideas: Have a way to mark visited points At the beginning, queue the start point. While the queue is not empty, continue dequeuing its element. And with each element Fill its color and mark just-dequeued point as visited Enqueue unvisited adjacent … Read more

Erase bitmap parts using PorterDuff mode

Here is working code… may help somebody public class ImageDemo extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new Panel(this)); } class Panel extends View { private Bitmap mBitmap; private Canvas mCanvas; private Path mPath; private Paint mPaint; Bitmap bitmap; Canvas pcanvas; int x = 0; int y =0; int r =0; public … Read more