Change image format and size

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 768
Благодарностей
1 179
Баллы
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();
 

huangxiangcai_old

Новичок
Регистрация
23.03.2013
Сообщения
25
Благодарностей
4
Баллы
3

Обращаем Ваше внимание на то, что данный пользователь заблокирован.
Не рекомендуем проводить с huangxiangcai_old какие-либо сделки.

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:)
 

huangxiangcai_old

Новичок
Регистрация
23.03.2013
Сообщения
25
Благодарностей
4
Баллы
3

Обращаем Ваше внимание на то, что данный пользователь заблокирован.
Не рекомендуем проводить с huangxiangcai_old какие-либо сделки.

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();
 

bigcajones

Client
Регистрация
09.02.2011
Сообщения
1 216
Благодарностей
681
Баллы
113
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.
 

huangxiangcai_old

Новичок
Регистрация
23.03.2013
Сообщения
25
Благодарностей
4
Баллы
3

Обращаем Ваше внимание на то, что данный пользователь заблокирован.
Не рекомендуем проводить с huangxiangcai_old какие-либо сделки.

rostonix

Известная личность
Регистрация
23.12.2011
Сообщения
29 067
Благодарностей
5 703
Баллы
113
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
 

huangxiangcai_old

Новичок
Регистрация
23.03.2013
Сообщения
25
Благодарностей
4
Баллы
3

Обращаем Ваше внимание на то, что данный пользователь заблокирован.
Не рекомендуем проводить с huangxiangcai_old какие-либо сделки.

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.
 

LexxWork

Client
Регистрация
31.10.2013
Сообщения
1 190
Благодарностей
785
Баллы
113
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();
 

ROWLIN

Новичок
Регистрация
02.04.2016
Сообщения
5
Благодарностей
0
Баллы
1
LexxWork how we can use your method to increase image size with saving its proportion

thanks
 

rostonix

Известная личность
Регистрация
23.12.2011
Сообщения
29 067
Благодарностей
5 703
Баллы
113

ROWLIN

Новичок
Регистрация
02.04.2016
Сообщения
5
Благодарностей
0
Баллы
1
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.
 

rostonix

Известная личность
Регистрация
23.12.2011
Сообщения
29 067
Благодарностей
5 703
Баллы
113
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.
 

rostonix

Известная личность
Регистрация
23.12.2011
Сообщения
29 067
Благодарностей
5 703
Баллы
113
That's what i usually do for my personal projects
 

ROWLIN

Новичок
Регистрация
02.04.2016
Сообщения
5
Благодарностей
0
Баллы
1
any way thanks
 

jsamesgsfus

Новичок
Регистрация
12.01.2018
Сообщения
1
Благодарностей
0
Баллы
1
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.
 

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