sorry but i dun get your meaning on transparent zone...
as for the show original image, just ignore image.resize and you will get back the original size of the image
Hello, and thank you for responding.
Look, I want to do is a run of images that are saved in a folder. In this folder there are pictures of type. png and. gif opacity with areas of 0, not if I understand, pixels without color, with translucent parts, and using this code, the translucent areas
become black, and let me know :
> How is to be displayed translícidas areas that are not replaced by black, perhaps they can understand me if you run the code.
> How would showing the picture in size considering that its dimensions are unknown.
> Or maybe should obtenet first the dimensions of the image, how would do that?
ha and another question. There is a page with full documentation of Razor?
And thanks for your reply.
Thanks for the reply, but I saw everyone webmatrix tutorials in asp.net and have noticed that there are only basic questions, but I wanted to know if there is full documentation of Razor, it is something like PHP with php.net.
Well, just wanted to ask you please aid me with my problem.
Look, if you have time, compare these two codes,
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Web.Helpers;
public static class ResizePng {
private static IDictionary<string, ImageFormat> _transparencyFormats = new Dictionary<string, ImageFormat>(StringComparer.OrdinalIgnoreCase)
{ {"png", ImageFormat.Png}, { "gif", ImageFormat.Gif} };
public static WebImage ResizePreserveTransparency(this WebImage image, int width, int height) {
ImageFormat format = null;
if (!_transparencyFormats.TryGetValue(image.ImageFormat, out format)) {
return image.Resize(width, height);
}
using (Image resizedImage = new Bitmap(width, height)) {
using (Bitmap source = new Bitmap(new MemoryStream(image.GetBytes()))) {
using (Graphics g = Graphics.FromImage(resizedImage)) {
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.DrawImage(source, 0, 0, width, height);
}
}
using (MemoryStream ms = new MemoryStream()) {
resizedImage.Save(ms, format);
return new WebImage(ms.ToArray());
}
}
}
}
Save the image as ResizeWebImage.cs under App_Code and you should be able to write image.ResizePreserveTransparency(200, 200).Write()
Marked as answer by jaspherlopez on Feb 24, 2011 11:24 PM
hello pranavkm, thanks for the reply, it has served me well, I can not model the size of the image at a thumbnail to resize the image without deforming,
but in the end helped me a lot of help.
jaspherlopez
Member
16 Points
9 Posts
How to keep the image transparent zones with WebImage require?
Feb 20, 2011 10:23 PM|LINK
How to keep the image transparent zones with WebImage require?
Hi, I saw that this function may require an image from a data base or from a file.
@{ Layout=""; var image = new WebImage(Href("~/Images/logo.png")); image.Resize(200,200).Write(); }But when I call the image, the transparent parts changed to black.
Is there any way to keep the transparent areas of the image?
How would showing the picture in real size?
Thanks for your help!
scngan
Participant
1650 Points
333 Posts
MVP
Re: How to keep the image transparent zones with WebImage require?
Feb 21, 2011 04:25 AM|LINK
sorry but i dun get your meaning on transparent zone...
as for the show original image, just ignore image.resize and you will get back the original size of the image
http://blog.scnetstudio.com
jaspherlopez
Member
16 Points
9 Posts
Re: How to keep the image transparent zones with WebImage require?
Feb 21, 2011 07:27 AM|LINK
Hello, and thank you for responding.
Look, I want to do is a run of images that are saved in a folder. In this folder there are pictures of type. png and. gif opacity with areas of 0, not if I understand, pixels without color, with translucent parts, and using this code, the translucent areas become black, and let me know :
> How is to be displayed translícidas areas that are not replaced by black, perhaps they can understand me if you run the code.
> How would showing the picture in size considering that its dimensions are unknown.
> Or maybe should obtenet first the dimensions of the image, how would do that?
ha and another question. There is a page with full documentation of Razor?
And thanks for your reply.
scngan
Participant
1650 Points
333 Posts
MVP
Re: How to keep the image transparent zones with WebImage require?
Feb 21, 2011 07:48 AM|LINK
hi jaspherlopez
here you go, the full api for razor syntax : http://www.asp.net/webmatrix/tutorials/asp-net-web-pages-api-reference
http://blog.scnetstudio.com
jaspherlopez
Member
16 Points
9 Posts
Re: How to keep the image transparent zones with WebImage require?
Feb 21, 2011 04:25 PM|LINK
Hi scngan
Thanks for the reply, but I saw everyone webmatrix tutorials in asp.net and have noticed that there are only basic questions, but I wanted to know if there is full documentation of Razor, it is something like PHP with php.net.
Well, just wanted to ask you please aid me with my problem.
Look, if you have time, compare these two codes,
This in PHP
<?php Header( "Content-type: image/png"); $imagen_png = file_get_contents('logo.png'); echo $imagen_png; ?>This in Razor
@{ Layout=""; var image = new WebImage(Href("~/Images/logo.png")); image.Resize(200,200).Write(); }comparing these two results with translucent images, and you will see that php if kept translucent but not Razor.
Thanks for the reply
pranavkm
Participant
796 Points
106 Posts
Re: How to keep the image transparent zones with WebImage require?
Feb 22, 2011 03:22 AM|LINK
It does look like the implementation of the Resize method is incorrect. It converts the image to a bitmap which results in loss of transparency.
Here's an helper based off a solution I found on StackOverflow (http://stackoverflow.com/questions/753968/why-does-resizing-a-png-image-lose-transparency). It seems to work well for regular png and gif files.
using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Web.Helpers; public static class ResizePng { private static IDictionary<string, ImageFormat> _transparencyFormats = new Dictionary<string, ImageFormat>(StringComparer.OrdinalIgnoreCase) { {"png", ImageFormat.Png}, { "gif", ImageFormat.Gif} }; public static WebImage ResizePreserveTransparency(this WebImage image, int width, int height) { ImageFormat format = null; if (!_transparencyFormats.TryGetValue(image.ImageFormat, out format)) { return image.Resize(width, height); } using (Image resizedImage = new Bitmap(width, height)) { using (Bitmap source = new Bitmap(new MemoryStream(image.GetBytes()))) { using (Graphics g = Graphics.FromImage(resizedImage)) { g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.DrawImage(source, 0, 0, width, height); } } using (MemoryStream ms = new MemoryStream()) { resizedImage.Save(ms, format); return new WebImage(ms.ToArray()); } } } }Save the image as ResizeWebImage.cs under App_Code and you should be able to write image.ResizePreserveTransparency(200, 200).Write()
jaspherlopez
Member
16 Points
9 Posts
Re: How to keep the image transparent zones with WebImage require?
Feb 24, 2011 11:24 PM|LINK
hello pranavkm, thanks for the reply, it has served me well, I can not model the size of the image at a thumbnail to resize the image without deforming, but in the end helped me a lot of help.