Change image format and size

  • Автор темы Автор темы lokiys
  • Дата начала Дата начала

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 922
Реакции
1 206
Баллы
113
C#:
Развернуть Свернуть Копировать
// Get image path
string imagePath = project.Variables["imagePath"].Value;
// Create image file
Bitmap tempBmp = new Bitmap(imagePath);
Bitmap bmp = new Bitmap(tempBmp, 1280, 720);
// Save new image
bmp.Save(project.Variables["finalImagePath"].Value, System.Drawing.Imaging.ImageFormat.Jpeg);
bmp.Dispose();
 
C#:
Развернуть Свернуть Копировать
// Get image path
string imagePath = project.Variables["imagePath"].Value;
// Create image file
Bitmap tempBmp = new Bitmap(imagePath);
Bitmap bmp = new Bitmap(tempBmp, 1280, 720);
// Save new image
bmp.Save(project.Variables["finalImagePath"].Value, System.Drawing.Imaging.ImageFormat.Jpeg);
bmp.Dispose();


Dear lokyis:

very appreciated with you FAST help !! O:)
 
Dear lokyis:

i have test in Zennoposter C# action .but some error taken .unable to get a new size images.
the system give me a information:"Exception has been thrown by the target of an invocation."
I want to install the Microsoft Visual C++ 2008. but it seems the visual c++ 2008 has been installed when i install the Zennoposter to my laptop.

How i can do now? i think i have set the right informations and vale for the variables.

the{-variable.imagepath-} value:"F:\ZP-Work\photos\Bags\MessengerBags\imagepath\10001.jpg"

the {-Variable.finalImagePath-} value at :"F:\ZP-Work\photos\Bags\MessengerBags\finalImagePath\10001.jpg"

it can be change the image fromat from:" .jpg" to " .jpeg" automatically?

the small size can be 640pix* 480pix
eg:
Bitmap bmp =new Bitmap(tempBmp, 640, 480);

if you can give me a zennoposter file .xml ?

sorry to take your time ,but i think i am very need to use this function via zennoposter actions.

God bless.thanks!
unableu to run3.jpg

C#:
Развернуть Свернуть Копировать
// Get image path
string imagePath = project.Variables["imagePath"].Value;
// Create image file
Bitmap tempBmp = new Bitmap(imagePath);
Bitmap bmp = new Bitmap(tempBmp, 1280, 720);
// Save new image
bmp.Save(project.Variables["finalImagePath"].Value, System.Drawing.Imaging.ImageFormat.Jpeg);
bmp.Dispose();
 
Try running it in debug, not in the C code tester. You have to physically type in a value in the tester for the variables in order to get it to work.
 
I didnt test the code but if lokiys says it works, it should work)
Try to check your variables. If you have correct data there
 
I didnt test the code but if lokiys says it works, it should work)
Try to check your variables. If you have correct data there
I didnt test the code but if lokiys says it works, it should work)
Try to check your variables. If you have correct data there
You always right.thanks Rostonix and Lokyis.
So the other problem is:how to write the images into Excel File?
----->>> I want to write a 150 x 150 pix product images to the Excel.<<-----------
Thanks agian.
 
Just improved example - reduce image with saving its proportion
Код:
Развернуть Свернуть Копировать
//Reduce image with saving its proportion
Func<System.Drawing.Image, int, int, System.Drawing.Image> imgReduse = (System.Drawing.Image _img, int _width, int _height) => {
var _rx = (double)_img.Width/_width;
var _ry = (double)_img.Height/_height;
var _ratio = Math.Min(_rx, _ry);
var _newW = (int)(_img.Width/_ratio);
var _newH = (int)(_img.Height/_ratio);
return new System.Drawing.Bitmap(_img, _newW, _newH);
};

string imagePath = @"D:\downloads\photo_51465.jpg";
// Create image file
System.Drawing.Image tempimg = System.Drawing.Image.FromFile(imagePath);
System.Drawing.Image img = imgReduse(tempimg, 300, 100);
// Save new image
img.Save(@"D:\downloads\small_photo_51465.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
tempimg.Dispose();
img.Dispose();
 
LexxWork how we can use your method to increase image size with saving its proportion

thanks
 
i appreciate your intersting Rostonix ,

what i'm trying to do is increase image sizes like in this website http://resizeimage.net/ without keeping the Aspect Ratio and Fill in the background with a color if the proportion of image changed.
 
i appreciate your intersting Rostonix ,

what i'm trying to do is increase image sizes like in this website http://resizeimage.net/ without keeping the Aspect Ratio and Fill in the background with a color if the proportion of image changed.
Oh i see. I'm not Pro in external C# methods which are not developed by Zennolab, cant help (((
But i think that kind of questions can be also solved on sites like stackoverflow since they are related to C#, not ZennoPoster. And when you will have solution for C# it is easy to replace paths to files with Zenno variables.
 
That's what i usually do for my personal projects
 
any way thanks
 
Hi guys, there is a new and better way to change the image size and optimize it online from this site https://www.resizejpeg.com/. this is a great website to change your image / gif / png / jpeg / with ease. I think you have to try it.
 

Кто просматривает тему: (Всего: 0, Пользователи: 0, Гости: 0)