照片存成viewcompress pdf什么意思

将UIImageView上的图片保存到相册中 - 简书
将UIImageView上的图片保存到相册中
如何把图片保存到iOS自带的相册中把UIImage所代表的图片保存到Photo Album中
想要实现上述功能可以使用UIKit框架下提供的一个方法
UIImageWriteToSavedPhotosAlbum(
UIImage * _Nonnull image,
_Nullable completionTarget,
_Nullable completionSelector,
void * _Nullable contextInfo
各参数说明:id是target对象,sel是selector,即target对象上的方法名,contextInfo是任意指针,会传递到selector定义的方法上。一般是当完成后调用方法时使用,或者在完成时出错的处理。
简单实现Demo:
//实现该方法
- (void)saveImageToPhotos:(UIImage*)savedImage
UIImageWriteToSavedPhotosAlbum(savedImage, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
//因为需要知道该操作的完成情况,即保存成功与否,所以此处需要一个回调方法image:didFinishSavingWithError:contextInfo:
//回调方法
- (void)image: (UIImage *) image didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo
NSString *msg =
if(error != NULL){
msg = @"保存图片失败" ;
msg = @"保存图片成功" ;
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:msg preferredStyle:UIAlertControllerStyleAlert];
[self showViewController:alert sender:nil];
//注iOS9弃用了UIAlertView类。
//调用方法
UIImage *savedImage = [UIImage imageNamed:@"111.png"];
[self saveImageToPhotos:savedImage];
值得注意的是,在访问系统相册时,系统会询问用户是否允许访问,如果用户不允许,则不能访问相册,保存肯定是失败的!!!像推送、通知、定位之类,都需要询问用户是否允许!!!
做一只骄傲的程序猿3071人阅读
Android(385)
package zhangphil.
import java.io.F
import java.io.FileOutputS
import android.os.B
import android.os.E
import android.os.H
import android.view.V
import android.widget.B
import android.widget.TextV
import android.app.A
import android.graphics.B
import android.graphics.C
import android.graphics.C
import android.graphics.P
* 把Android的一个View转换成图片保存
public class MainActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView tv = (TextView) findViewById(R.id.textView);
tv.setBackgroundColor(Color.GREEN);
// tv.setDrawingCacheEnabled(true);
final Runnable runnable = new Runnable() {
public void run() {
viewSaveToImage(tv);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
new Handler().post(runnable);
public void viewSaveToImage(View view) {
view.setDrawingCacheEnabled(true);
view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
view.setDrawingCacheBackgroundColor(Color.WHITE);
// 把一个View转换成图片
Bitmap cachebmp = loadBitmapFromView(view);
// 添加水印
Bitmap bitmap = Bitmap.createBitmap(createWatermarkBitmap(cachebmp,
&@ Zhang Phil&));
FileOutputS
// 判断手机设备是否有SD卡
boolean isHasSDCard = Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_MOUNTED);
if (isHasSDCard) {
// SD卡根目录
File sdRoot = Environment.getExternalStorageDirectory();
File file = new File(sdRoot, &test.PNG&);
fos = new FileOutputStream(file);
throw new Exception(&创建文件失败!&);
pressFormat.PNG, 90, fos);
fos.flush();
fos.close();
} catch (Exception e) {
e.printStackTrace();
view.destroyDrawingCache();
private Bitmap loadBitmapFromView(View v) {
int w = v.getWidth();
int h = v.getHeight();
Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bmp);
c.drawColor(Color.WHITE);
/** 如果不设置canvas画布为白色,则生成透明 */
v.layout(0, 0, w, h);
v.draw(c);
// 为图片target添加水印
private Bitmap createWatermarkBitmap(Bitmap target, String str) {
int w = target.getWidth();
int h = target.getHeight();
Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bmp);
Paint p = new Paint();
// 水印的颜色
p.setColor(Color.RED);
// 水印的字体大小
p.setTextSize(16);
p.setAntiAlias(true);// 去锯齿
canvas.drawBitmap(target, 0, 0, p);
// 在中间位置开始添加水印
canvas.drawText(str, w / 2, h / 2, p);
canvas.save(Canvas.ALL_SAVE_FLAG);
canvas.restore();
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:705275次
积分:11143
积分:11143
排名:第1213名
原创:402篇
转载:14篇
评论:140条
(5)(14)(4)(1)(1)(6)(12)(9)(7)(22)(27)(10)(9)(9)(1)(16)(42)(40)(43)(20)(26)(12)(4)(9)(11)(19)(45)温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
Bitmap bitmap=BitmapFactory.decodeFile(filePath);如果图片过大,可能导致Bitmap对象装不下图片解决办法:String filePath="c:/01.jpg"; Bitmap bitmap=BitmapFactory.decodeFile(filePath,getBitmapOption(2)); //将图片的长和宽缩小味原来的1/2private Options getBitmapOption(int inSampleSize){&&& &&& System.gc();&&& &&& BitmapFactory.Options options = new BitmapFactory.Options();&&& &&& options.inPurgeable =&&&&&&& options.inSampleSize = inSampleS&&&&&&&}Bitmap对象保存味图片文件public void saveBitmapFile(Bitmap bitmap){&&&&&&&&&&& File file=new File("/mnt/sdcard/pic/01.jpg");//将要保存图片的路径&&&& & & && try {&&& &&&&&&&&&&& &&& BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));&&& &&& &&&&&&&&&&& pressFormat.JPEG, 100, bos);&&& &&& &&& &&& &&& bos.flush();&&& &&& &&& &&& &&& bos.close();&&& &&& &&& } catch (IOException e) {&&& &&& &&& &&& &&& e.printStackTrace();&&& &&& &&& }}
阅读(50700)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
loftPermalink:'',
id:'fks_',
blogTitle:'图片文件和Bitmap之间的转换',
blogAbstract:'图片文件转为Bitmap对象String filePath=\"c:/01.jpg\";Bitmap bitmap=BitmapFactory.decodeFile(filePath);如果图片过大,可能导致Bitmap对象装不下图片解决办法:String filePath=\"c:/01.jpg\"; Bitmap bitmap=BitmapFactory.decodeFile(filePath,getBitmapOption(2)); //将图片的长和宽缩小味原来的1/2',
blogTag:'',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:2,
publishTime:0,
permalink:'blog/static/',
commentCount:0,
mainCommentCount:0,
recommendCount:2,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'',
hmcon:'0',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}}

我要回帖

更多关于 php gzcompress 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信