缩放图片代码

£神魔★判官ぃ 2022-08-22 06:26 376阅读 0赞
  • ( UIImage *)imageWithImageSimple:( UIImage *)image scaledToSize:( CGSize )newSize{
  1. // Create a graphics image context
  2. // 创建一个bitmap的context
  3. // 并把它设置成为当前正在使用的context
  4. //Determine whether the screen is retina
  5. if(\[\[UIScreen mainScreen\] scale\] == 3.0)\{
  6. UIGraphicsBeginImageContextWithOptions(newSize, NO, 3.0);
  7. \}elseif (\[\[UIScreen mainScreen\] scale\] == 2.0)\{
  8. UIGraphicsBeginImageContextWithOptions(newSize, NO, 2.0);
  9. \}else\{
  10. UIGraphicsBeginImageContext(newSize);
  11. \}
  12. // UIGraphicsBeginImageContext (newSize);
  13. // Tell the old image to draw in this new context, with the desired
  14. // new size
  15. \[image drawInRect : CGRectMake ( 0 , 0 ,newSize. width ,newSize. height )\];
  16. // Get the new image from the context
  17. UIImage \* newImage = UIGraphicsGetImageFromCurrentImageContext ();
  18. // End the context
  19. UIGraphicsEndImageContext ();
  20. // Return the new image.
  21. return newImage;
  22. \}

发表评论

表情:
评论列表 (有 0 条评论,376人围观)

还没有评论,来说两句吧...

相关阅读

    相关 图片焦点

    放大和缩小某个对象可能希望焦点锁定在特定位置。 例如看一张照片,假设照片的(0,0,0)在中心位置,我们来放大脸部。如果只是Scale放大,Postion并没有变化,导致图

    相关 java代码图片

    图片处理 在android中因为不同像素手机的多样化,对于一张图片,放大不同的手机上因像素不同显示上也会有区别。 现有如下需求:将一张图片宽度充满整个屏幕并显示。 我

    相关 Glide 图片

    CenterCrop CenterCrop()会缩放图像,完全填充到 ImageView 界限内并且裁剪额外的部分,图像可能不会完整显示。 Glide.with