How can I resize an image using Java?

FWIW I just released (Apache 2, hosted on GitHub) a simple image-scaling library for Java called imgscalr (available on Maven central). The library implements a few different approaches to image-scaling (including Chris Campbell’s incremental approach with a few minor enhancements) and will either pick the most optimal approach for you if you ask it to, … Read more

Send inline image in email

Some minimal c# code to embed an image, can be: MailMessage mailWithImg = GetMailWithImg(); MySMTPClient.Send(mailWithImg); //* Set up your SMTPClient before! private MailMessage GetMailWithImg() { MailMessage mail = new MailMessage(); mail.IsBodyHtml = true; mail.AlternateViews.Add(GetEmbeddedImage(“c:/image.png”)); mail.From = new MailAddress(“yourAddress@yourDomain”); mail.To.Add(“recipient@hisDomain”); mail.Subject = “yourSubject”; return mail; } private AlternateView GetEmbeddedImage(String filePath) { LinkedResource res = new LinkedResource(filePath); … Read more

Drag and drop files into WPF

This is basically what you want to do. private void ImagePanel_Drop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { // Note that you can have more than one file. string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); // Assuming you have one file that you care about, pass it off to whatever // handling code you have defined. HandleFileOpen(files[0]); } … Read more

Disable cache for some images

A common and simple solution to this problem that feels like a hack but is fairly portable is to add a randomly generated query string to each request for the dynamic image. So, for example – <img src=”https://stackoverflow.com/questions/728616/image.png” /> Would become <img src=”https://stackoverflow.com/questions/728616/image.png?dummy=8484744″ /> Or <img src=”https://stackoverflow.com/questions/728616/image.png?dummy=371662″ /> From the point of view of the … Read more

Gmail’s new image caching is breaking image links in newsletter

I think I have figured out the GoogleImageProxy issue. This is something related to CACHING concept. suppose, you have recently deployed your PHP code on your server but you forgot to upload images. you tested once with your email logic. your system generated an HTML email. When this email will hit the Gmail server GoogleImageProxy … Read more

Detect when an image fails to load in JavaScript

You could try the following code. I can’t vouch for browser compatibility though, so you’ll have to test that. function testImage(URL) { var tester=new Image(); tester.onload=imageFound; tester.onerror=imageNotFound; tester.src=URL; } function imageFound() { alert(‘That image is found and loaded’); } function imageNotFound() { alert(‘That image was not found.’); } testImage(“http://foo.com/bar.jpg”); And my sympathies for the jQuery-resistant … Read more

Is there a way to take a screenshot using Java and save it to some sort of image?

Believe it or not, you can actually use java.awt.Robot to “create an image containing pixels read from the screen.” You can then write that image to a file on disk. I just tried it, and the whole thing ends up like: Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()); BufferedImage capture = new Robot().createScreenCapture(screenRect); ImageIO.write(capture, “bmp”, new File(args[0])); … Read more

Convert HttpPostedFileBase to byte[]

As Darin says, you can read from the input stream – but I’d avoid relying on all the data being available in a single go. If you’re using .NET 4 this is simple: MemoryStream target = new MemoryStream(); model.File.InputStream.CopyTo(target); byte[] data = target.ToArray(); It’s easy enough to write the equivalent of CopyTo in .NET 3.5 … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)