110,538
社区成员
发帖
与我相关
我的任务
分享
for (int i = 0; i < MyClass.pictures.Count; i++)
{
backgroundWorker1.ReportProgress(i * 100 / (MyClass.picCount-1), 0); //报告进度
Bitmap bmp = new Bitmap(MyClass.pictures[i]); //new一个Bitmap,pictures里面存的是完整路径
bmp = MyClass.ResizeImage(bmp, bmp.Width / 2, bmp.Height / 2); //尺寸变为一半
string tmp = pathLv1 + MyClass.pictures[i].Remove(0, MyClass.pictures[i].LastIndexOf("\\")); //新路径+原来的图片名字
bmp.Save(tmp, ImageFormat.Jpeg); //保存图片为jpg格式
if (total >100) //如果总数量大于100 --------------在这里报错“参数无效”??
{
bmp = MyClass.ResizeImage((Bitmap)bmp, bmp.Width / 2, bmp.Height / 2); //尺寸变为最初的四分之一
bmp.Save(pathLv2 + MyClass.pictures[i].Remove(0, MyClass.pictures[i].LastIndexOf("\\")));
}
bmp.Dispose(); //释放bmp资源
int total=MyClass.picCount;
就这一句啊,pictureCount也是有值的,代码如下:
/// <summary>
/// 图片总数量
/// </summary>
public static int picCount { get; set; }
当执行到for的时候,这个一定有值,值为100或200