我有一个带有图片库的应用程序,我希望用户可以将其保存到自己的图库中.我已经创建了一个带有单个声音"保存"的选项菜单,但问题是......我怎样才能将图像保存到图库中?
这是我的代码:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.menuFinale:
imgView.setDrawingCacheEnabled(true);
Bitmap bitmap = imgView.getDrawingCache();
File root = Environment.getExternalStorageDirectory();
File file = new File(root.getAbsolutePath()+"/DCIM/Camera/img.jpg");
try
{
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
bitmap.compress(CompressFormat.JPEG, 100, ostream);
ostream.close();
}
catch (Exception e)
{
e.printStackTrace();
}
return true;
default:
return super.onOptionsItemSelected(item);
}
}
Run Code Online (Sandbox Code Playgroud)
我不确定这部分代码:
File root = Environment.getExternalStorageDirectory();
File file = new File(root.getAbsolutePath()+"/DCIM/Camera/img.jpg");
Run Code Online (Sandbox Code Playgroud)
保存到画廊是否正确?不幸的是代码不起作用:(
我正在尝试将图像保存到Swift 3中的照片库(我正在使用Xcode 8).
ViewController代码:
func shareImage(image: UIImage) {
let items = [image]
var activityVC: UIActivityViewController = UIActivityViewController(activityItems: items, applicationActivities: nil)
let excludeActivities: [UIActivityType] = [UIActivityType.airDrop,
UIActivityType.assignToContact,
UIActivityType.addToReadingList,
UIActivityType.copyToPasteboard]
activityVC.excludedActivityTypes = excludeActivities
self.present(activityVC, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
当我运行应用程序,然后单击按钮获取屏幕截图(将其转换为图像,......,这一切都完美无缺)时,应用程序要求访问照片库的权限,我点击"确定"按钮,然后应用程序崩溃.图像未保存在照片库中.
我从Xcode获得的唯一线索如下:
2016-09-28 11:24:27.216043 Ajax Kids[4143:1545362] [error] error: -addPersistentStoreWithType:SQLite configuration:(null) URL:file:///var/mobile/Media/PhotoData/Photos.sqlite?readonly_shm=1 options:{
NSPersistentStoreFileProtectionKey = NSFileProtectionCompleteUntilFirstUserAuthentication;
NSReadOnlyPersistentStoreOption = 1;
NSSQLitePersistWALOption = 1;
NSSQLitePragmasOption = {
"journal_mode" = WAL;
};
} ... returned error Error Domain=NSCocoaErrorDomain Code=256 "The file couldn’t be opened." UserInfo={reason=Failed to access …Run Code Online (Sandbox Code Playgroud) 如何将图像(如使用UIImageWriteToSavedPhotosAlbum()方法)与我选择的文件名保存到private/var文件夹中?
在我的应用程序中,我需要允许用户右键单击图像以将图像保存到磁盘.但是,我注意到,使用我的特定代码,谷歌浏览器是唯一不允许用户"将图像另存为..."的浏览器,除非用户首先选择Open image in new tab,然后从那里选择Save image as...
由于所有其他主流浏览器(包括移动Chrome)都按预期工作,我不确定我是不是以标准/正确的方式实现我的代码,或者问题是否与Chrome有关.
例:
以下HTML是我正在做的精简版.它将允许您单击按钮以打开将包含图像的新窗口.
要测试/确认我上面描述的问题,请右键单击图像并选择Save image as..- 您应该注意到没有任何反应.但是,如果右键单击图像并选择Open image in new tab,则可以Save image as..从那里进行操作.
<html>
<head>
<title></title>
<script>
function foo() {
var tab = window.open();
tab.document.write('<p>Right-click, then click "Save image as ..."</p><img src="http://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-icon.png" />');
}
</script>
</head>
<body>
<button onclick="foo();">Open</button>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
这是Chrome存在的问题,或者是有另一种方式,我可以使用window.open()连同document.write()获得Chrome浏览器像其他浏览器(即不必首先选择Open image in new tab.
我的网站上有一个页面,显示了我的PHP生成的一些图像.当我右键单击图像并单击"保存图像"时,我将默认名称作为用于生成图像的php文件的名称.
这是例如图像的html:
<img src="picture_generator.php?image_id=5&extension=.png">
Run Code Online (Sandbox Code Playgroud)
我得到的名字是:picture_generator.php.png
有没有办法将此名称设置为默认名称?
提前致谢
我只是想以编程方式将显示的小部件保存在我的计算机上。我尝试使用捕获和输出。我希望有一个名为 .savefig() 的方法
我看过这个问题,Save iPython Jupyter Notebook Widgets to PNG/PDF/JPG/GIF但没有答案。
我只是想将滑块对象保存到我的计算机文件系统,例如 myimage.jpeg

这是代码
import ipywidgets as wg
from IPython.display import display
w = wg.IntSlider(description='Test Slider',min=1,max=25)
w.value=14
display(w)
#Question is how to save this test slider as image output ??
Run Code Online (Sandbox Code Playgroud) 我想将上传的文件(例如用户的头像图像)保存到MongoDB中的用户集合中,我想以下步骤是:
我这是对的吗?你能给我一些线索吗?
我有一个基本图像视图,可以从SD卡加载图像.用户可以templates(bitmap images)通过点击按钮添加到此图像视图,并可以将添加的图像定位到用户需要.我想将这些多个图像作为单个图像保存到SD卡.我怎样才能做到这一点?
我在通过 GIMP 在 python 中保存图像时遇到问题。我可以获得图像并应用我想要的效果,但是当我去保存时,它只保存一层而不是所有内容(注意:背景是透明的)并且因为背景是透明的,所以我无法保存任何东西透明背景。我正在使用的代码发布在下面:
image_array = gimp.image_list()
i=0
for image in image_array:
img = image_array[i]
layers = img.layers
last_layer = len(layers)-1
try:
disable=pdb.gimp_image_undo_disable(img)
pdb.gimp_layer_add_alpha(layers[0])
drw = pdb.gimp_image_active_drawable(img)
pdb.plug_in_colortoalpha(img,drw,(0,0,0))
drw = pdb.gimp_image_active_drawable(img)
enable = pdb.gimp_image_undo_enable(img)
except:
print "ERROR"
pdb.file_png_save(img, drw, "C:\\Users\\jammer\\Desktop\\test.png",
"test.png",0,9,1,1,1,1,1)
i+=1
Run Code Online (Sandbox Code Playgroud)
我也尝试过file_png_save2,但我感觉问题出在 drw 对象中,因为我只想复制单击文件->导出并另存为 PNG的选项,而无需通过 GUI 执行此操作。我宁愿让它自动保存(我有 49 个图像,每个图像都会自动命名,但首先我需要让它用一张图像正确导出)。正如我之前所说,上面的代码只导出透明背景,即使更改为 GIF 也不能解决问题。如何在保留所有图层和透明背景的同时将文件导出为 PNG?
我有一个 div,它获取用户图像并将用户文本放在上面。我的目标是让用户在看到预览并根据自己的喜好自定义图像/文本后,能够通过单击按钮来下载或保存图像。这可能吗?这是我的代码:(我是 html/css 新手,所以请原谅丑陋的格式/方法)
HTML:
<script `src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.min.js"></script>`
<p>DOM-rendered</p>
<p> </p>
<div id="imagewrap" class="wrap" style="border-style: solid;">
<img src="../images/environment.gif" id="img_prev" width="640" height="640" />
<h3 class="desc">Something Inspirational</h3>
</div>
<div id="canvasWrapper" class="outer">
<p>Canvas-rendered (try right-click, save image as!)</p>
<p>Or, <a id="downloadLink" download="cat.png">Click Here to Download!</a>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
.desc {
text-align: center;
}
.outer, .wrap, .html2canvas, .image_text {
display: inline-block;
vertical-align: top;
}
.wrap {
text-align: center;
}
#imagewrap {
background-color: white;
}
Run Code Online (Sandbox Code Playgroud)
JavaScript:
window.onload = function() {
html2canvas(document.getElementById("imagewrap"), {
onrendered: function(canvas) {
canvas.className = "html2canvas"; …Run Code Online (Sandbox Code Playgroud)