Change image format and size

lokiys

Moderator
Joined
Feb 1, 2012
Messages
4,858
Reaction score
1,193
Points
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

Новичок
Joined
Mar 23, 2013
Messages
25
Reaction score
4
Points
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

Новичок
Joined
Mar 23, 2013
Messages
25
Reaction score
4
Points
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
Joined
Feb 9, 2011
Messages
1,216
Reaction score
684
Points
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

Новичок
Joined
Mar 23, 2013
Messages
25
Reaction score
4
Points
3

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

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.
sure i have test in debug ,and also type the vale in tester but the problem still.
 

rostonix

Известная личность
Joined
Dec 23, 2011
Messages
29,067
Reaction score
5,718
Points
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

Новичок
Joined
Mar 23, 2013
Messages
25
Reaction score
4
Points
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
Joined
Oct 31, 2013
Messages
1,190
Reaction score
792
Points
113
Just improved example - reduce image with saving its proportion
Code:
//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

Новичок
Joined
Apr 2, 2016
Messages
5
Reaction score
0
Points
1
LexxWork how we can use your method to increase image size with saving its proportion

thanks
 

rostonix

Известная личность
Joined
Dec 23, 2011
Messages
29,067
Reaction score
5,718
Points
113

ROWLIN

Новичок
Joined
Apr 2, 2016
Messages
5
Reaction score
0
Points
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

Известная личность
Joined
Dec 23, 2011
Messages
29,067
Reaction score
5,718
Points
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

Известная личность
Joined
Dec 23, 2011
Messages
29,067
Reaction score
5,718
Points
113
That's what i usually do for my personal projects
 

ROWLIN

Новичок
Joined
Apr 2, 2016
Messages
5
Reaction score
0
Points
1
any way thanks
 

jsamesgsfus

Новичок
Joined
Jan 12, 2018
Messages
1
Reaction score
0
Points
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.
 

Users Who Are Viewing This Thread (Total: 1, Members: 0, Guests: 1)