- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我无法加载所选图像。正在加载默认模板图像。我用帖子中的完整 fragment 代码编辑了它,您能指导我使用哪个参数上传到所选图像吗?
以下更新后的代码可以工作,但只能上传预定义的图像,我无法上传所选图像,我不知道该行上使用哪个参数
if (this.imageUri != imageUri && requestCode == IMAGE_PICK_CODE && resultCode == RESULT_OK) {
class ReportFragment : Fragment(), OnMapReadyCallback, GoogleMap.OnMapClickListener, GoogleMap.OnCameraIdleListener {
private var mMapView: MapView? = null
private var map: GoogleMap? = null
val CAMERA_PERMISSION_CODE = 0
val CAMERA_REQUEST_CODE = 10
lateinit var imageFilePath: String
private var imgThumb: ImageView? = null
private var spinner: Spinner? = null
private var currentLocation: LatLng? = null // TODO: get current location as static variable
private var midLatLng: LatLng? = null
private var lat: Double? = null
private var lng: Double? = null
private var objectValues: Array<String>? = null
private var imageUri: Uri? = null
private var pictureTaken: Boolean = false
private var progress: ProgressBar? = null
val PERMISSION_CODE_READ = 1001
val PERMISSION_CODE_WRITE = 1002
val IMAGE_PICK_CODE = 1000
private val database: FirebaseDatabase? = FirebaseDatabase.getInstance()
private val markersRef: DatabaseReference? = database!!.getReference("markers")
private val storage = FirebaseStorage.getInstance()
private val storageRef: StorageReference = storage.reference
private var imagesRef: StorageReference? = null
private val permissoes = arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE)
inner class GenericFileProvider : FileProvider()
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
ContextCompat.checkSelfPermission(this.context,
Manifest.permission.READ_EXTERNAL_STORAGE)
ContextCompat.checkSelfPermission(this.context,
Manifest.permission.WRITE_EXTERNAL_STORAGE)
Permissoes.validarPermissoes(permissoes, this.activity, 1)
// Inflate the layout for this fragment
val view = inflater.inflate(R.layout.fragment_report, container, false)
if (arguments != null && arguments.getDouble("lat") != null) {
this.lat = arguments.getDouble("lat")
this.lng = arguments.getDouble("lng")
}
this.objectValues = resources.getStringArray(R.array.object_values) // for dropdown
// TODO this.currentLocation = Utils.currentLocation
this.progress = view.findViewById(R.id.progressBar) as ProgressBar
// Needs to call MapsInitializer before doing any CameraUpdateFactory calls
try {
initMap(view, savedInstanceState)
} catch (e: GooglePlayServicesNotAvailableException) {
e.printStackTrace()
}
this.imgThumb = view.findViewById(R.id.takePictureThumbnail) as ImageButton
val camBtn = view.findViewById(R.id.takePictureBtn) as ImageButton
val createBtn = view.findViewById(R.id.createIssueBtn) as Button
camBtn.setOnClickListener{
pickImageFromGallery()
}
this.imgThumb!!.setOnClickListener{
takePicture()
}
this.spinner = view.findViewById<Spinner>(R.id.object_types_spinner)
// Create an ArrayAdapter using the string array and a default spinner layout
val adapter = ArrayAdapter.createFromResource(context, R.array.object_types, android.R.layout.simple_spinner_item)
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
this.spinner!!.adapter = adapter
createBtn.setOnClickListener{
createIssue(view)
}
return view
}
fun createIssue(view: View) {
this.progress!!.visibility = View.VISIBLE
val layout = view.findViewById<LinearLayout>(R.id.reportLinearLayout)
layout.alpha = 0.4f
val random = UUID.randomUUID().toString()
val imgUrl = "images/issue$random+.jpg"
val name = view.findViewById<EditText>(R.id.issueNameEditText).text.toString()
val desc = view.findViewById<EditText>(R.id.issueDescriptionEditText).text.toString()
val type = this.objectValues!![this.spinner!!.selectedItemPosition]
var issue = Issue(name, type, this.midLatLng!!.latitude, this.midLatLng!!.longitude, desc, imgUrl, null)
this.imagesRef = storageRef.child(imgUrl)
var uploadTask: UploadTask = this.imagesRef!!.putBytes(putImgToBytearray())
uploadTask.addOnSuccessListener { taskSnapshot ->
this.progress!!.visibility = View.GONE
Toast.makeText(context,"upload Done",Toast.LENGTH_LONG).show()
markersRef!!.child(random).setValue(issue)
goToDetailsView(issue)
}.addOnFailureListener {
this.progress!!.visibility = View.GONE
Toast.makeText(context,"upload failed",Toast.LENGTH_LONG).show()
}.addOnProgressListener {
var prog: Double = (100.0 * it.bytesTransferred )/ it.totalByteCount
Log.i("transfer", prog.toString())
//this.progress!!.setProgress(prog.toInt(), true)
}
}
private fun goToDetailsView(issue: Issue) {
val args = Bundle()
val detailsFragment = IssueDetailsFragment()
args.putDouble("lat", issue.lat)
args.putDouble("lng", issue.lng)
args.putString("description", issue.description)
args.putString("name", issue.name)
args.putString("type", issue.type)
args.putString("imgUrl", issue.imgUrl)
detailsFragment.arguments = args
val ft = fragmentManager.beginTransaction()
ft.replace(R.id.main_fragment_content, detailsFragment)
.setTransition(android.app.FragmentTransaction.TRANSIT_FRAGMENT_FADE)
.addToBackStack(null).commit()
}
private fun putImgToBytearray(): ByteArray {
val stream = ByteArrayOutputStream()
val drawable = this.imgThumb!!.drawable as BitmapDrawable
val bitmap = drawable.bitmap
bitmap.compress(Bitmap.CompressFormat.JPEG, 70, stream)
return stream.toByteArray()
}
private fun initMap(view: View, savedInstanceState: Bundle?) {
MapsInitializer.initialize(this.activity)
mMapView = view.findViewById(R.id.mapView)
mMapView!!.onCreate(savedInstanceState)
mMapView!!.onResume() //without this, map showed but was empty
mMapView!!.getMapAsync(this)
}
override fun onMapClick(latLan: LatLng) {
this.map!!.addMarker(MarkerOptions().position(latLan).title("Marker"))
}
/**
* Open a camera activity with the picture returned as a result to onActivityResult
*/
fun openCamera() {
try {
val imageFile = createImageFile()
val callCameraIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
if(callCameraIntent.resolveActivity(activity.packageManager) != null) {
val authorities = activity.packageName + ".fileprovider"
this.imageUri = FileProvider.getUriForFile(context, authorities, imageFile)
callCameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri)
startActivityForResult(callCameraIntent, IMAGE_PICK_CODE)
}
} catch (e: IOException) {
Toast.makeText(context, "Could not create file!", Toast.LENGTH_SHORT).show()
}
}
/**
* take a picture but check for camera permissions first
*/
fun takePicture() {
val permissionGranted = ActivityCompat.checkSelfPermission(activity, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED
if (permissionGranted) {
openCamera()
} else {
ActivityCompat.requestPermissions(activity, arrayOf(Manifest.permission.CAMERA), CAMERA_PERMISSION_CODE)
}
}
private fun checkPermissionForImage() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if ((checkSelfPermission(this.context, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED)
&& (checkSelfPermission(this.context, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED)
) {
val permission = arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE)
val permissionCoarse = arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE)
requestPermissions(permission, PERMISSION_CODE_READ) // GIVE AN INTEGER VALUE FOR PERMISSION_CODE_READ LIKE 1001
requestPermissions(permissionCoarse, PERMISSION_CODE_WRITE) // GIVE AN INTEGER VALUE FOR PERMISSION_CODE_WRITE LIKE 1002
} else {
pickImageFromGallery()
}
}
}
private fun pickImageFromGallery() {
val intent = Intent(Intent.ACTION_PICK)
intent.type = "image/*"
startActivityForResult(intent, IMAGE_PICK_CODE ) // GIVE AN INTEGER VALUE FOR IMAGE_PICK_CODE LIKE 1000
}
/**
* Open the camera after obtaining the permission
*/
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
when (requestCode) {
CAMERA_PERMISSION_CODE -> {
if (grantResults.isEmpty() || grantResults[0] != PackageManager.PERMISSION_GRANTED) {
Log.i("CAMERA", "Permission has been denied by user")
} else {
openCamera()
Log.i("CAMERA", "Permission has been granted by user")
}
}
}
}
/**
* Save the picture to the thumbnail after taking it
*/
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (this.imageUri != imageUri && requestCode == IMAGE_PICK_CODE && resultCode == RESULT_OK) {
try {
pickImageFromGallery()
//Getting the Bitmap from Gallery
val bitmap = MediaStore.Images.Media.getBitmap(context.contentResolver, this.imageUri) as Bitmap
this.imgThumb!!.setImageBitmap(bitmap)
this.pictureTaken = true
} catch (e:IOException) {
e.printStackTrace()
}
} else {
Toast.makeText(context, "Error loading image", Toast.LENGTH_LONG)
}
}
@Throws(IOException::class)
fun createImageFile(): File {
val timeStamp: String = SimpleDateFormat("yyyyMMdd_HHmmss").format(Date())
val imageFileName: String = "JPEG_" + timeStamp + "_"
val storageDir: File = activity.getExternalFilesDir(Environment.DIRECTORY_PICTURES)
if(!storageDir.exists()) storageDir.mkdirs()
val imageFile = File.createTempFile(imageFileName, ".jpg", storageDir)
imageFilePath = imageFile.absolutePath
return imageFile
}
/**
* update the the coordinated of the map center when moving the map
*/
override fun onCameraIdle() {
this.midLatLng = this.map!!.cameraPosition.target
}
override fun onMapReady(googleMap: GoogleMap?) {
this.map = googleMap
this.map!!.setOnCameraIdleListener(this)
this.map!!.setOnMapClickListener(this)
if (this.lat != null) {
this.map!!.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(this.lat!!, this.lng!!), 8f))
} else if(this.currentLocation != null) { // TODO
this.map!!.moveCamera(CameraUpdateFactory.newLatLngZoom(this.currentLocation, 8f))
} else {
this.map!!.moveCamera(CameraUpdateFactory.newLatLngZoom(Utils.vienna, 8f)) // Vienna
}
}
override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
}
override fun onResume() {
super.onResume()
mMapView!!.onResume()
}
override fun onStart() {
super.onStart()
mMapView!!.onStart()
}
override fun onPause() {
super.onPause()
mMapView!!.onPause()
}
override fun onDestroy() {
super.onDestroy()
mMapView!!.onDestroy()
}
override fun onLowMemory() {
super.onLowMemory();
mMapView!!.onLowMemory();
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
mMapView!!.onSaveInstanceState(outState)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
override fun onDetach() {
super.onDetach()
}
}// Required empty public constructor
最佳答案
这是一个空指针异常。 imageUri 为空
MediaStore.Images.Media.getBitmap(context.contentResolver, this.imageUri) as Bitmap
如果你检查 getBitmap() 的实现。
参见
public static final Bitmap getBitmap(ContentResolver cr, Uri url)
throws FileNotFoundException, IOException {
InputStream input = cr.openInputStream(url);
Bitmap bitmap = BitmapFactory.decodeStream(input);
input.close();
return bitmap;
}
你会发现它调用了 openInputStream() ,它需要一个非空的 uri。
public final @Nullable InputStream openInputStream(@NonNull Uri uri)
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (this.imageUri != null && requestCode == IMAGE_PICK_CODE && resultCode == RESULT_OK) {
try {
//Getting the Bitmap from Gallery
val bitmap = MediaStore.Images.Media.getBitmap(context.contentResolver, this.imageUri) as Bitmap
this.imgThumb!!.setImageBitmap(bitmap)
this.pictureTaken = true
} catch (e:IOException) {
e.printStackTrace()
}
} else {
Toast.makeText(context, "Error loading image", Toast.LENGTH_LONG)
}
}
关于java - 从图库中选择的图像出现 Kotlin 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55944238/
我正在尝试学习 Knockout 并尝试创建一个照片 uploader 。我已成功将一些图像存储在数组中。现在我想回帖。在我的 knockout 码(Javascript)中,我这样做: 我在 Jav
我正在使用 php 编写脚本。我的典型问题是如何在 mysql 中添加一个有很多替代文本和图像的问题。想象一下有机化学中具有苯结构的描述。 最有效的方法是什么?据我所知,如果我有一个图像,我可以在数据
我在两个图像之间有一个按钮,我想将按钮居中到图像高度。有人可以帮帮我吗? Entrar
下面的代码示例可以在这里查看 - http://dev.touch-akl.com/celebtrations/ 我一直在尝试做的是在 Canvas 上绘制 2 个图像(发光,然后耀斑。这些图像的链接
请检查此https://jsfiddle.net/rhbwpn19/4/ 图像预览对于第一篇帖子工作正常,但对于其他帖子则不然。 我应该在这里改变什么? function readURL(input)
我对 Canvas 有疑问。我可以用单个图像绘制 Canvas ,但我不能用单独的图像绘制每个 Canvas 。- 如果数据只有一个图像,它工作正常,但数据有多个图像,它不工作你能帮帮我吗? va
我的问题很简单。如何获取 UIImage 的扩展类型?我只能将图像作为 UIImage 而不是它的名称。图像可以是静态的,也可以从手机图库甚至文件路径中获取。如果有人可以为此提供一点帮助,将不胜感激。
我有一个包含 67 个独立路径的 SVG 图像。 是否有任何库/教程可以为每个路径创建单独的光栅图像(例如 PNG),并可能根据路径 ID 命名它们? 最佳答案 谢谢大家。我最终使用了两个答案的组合。
我想将鼠标悬停在一张图片(音乐专辑)上,然后播放一张唱片,所以我希望它向右移动并旋转一点,当它悬停时我希望它恢复正常动画片。它已经可以向右移动,但我无法让它随之旋转。我喜欢让它尽可能简单,因为我不是编
Retina iOS 设备不显示@2X 图像,它显示 1X 图像。 我正在使用 Xcode 4.2.1 Build 4D502,该应用程序的目标是 iOS 5。 我创建了一个测试应用(主/细节)并添加
我正在尝试从头开始以 Angular 实现图像 slider ,并尝试复制 w3school基于图像 slider 。 下面我尝试用 Angular 实现,谁能指导我如何使用 Angular 实现?
我正在尝试获取图像的图像数据,其中 w= 图像宽度,h = 图像高度 for (int i = x; i imageData[pos]>0) //Taking data (here is the pr
我的网页最初通过在 javascript 中动态创建图像填充了大约 1000 个缩略图。由于权限问题,我迁移到 suPHP。现在不用标准 标签本身 我正在通过这个 php 脚本进行检索 $file
我正在尝试将 python opencv 图像转换为 QPixmap。 我按照指示显示Page Link我的代码附在下面 img = cv2.imread('test.png')[:,:,::1]/2
我试图在这个 Repository 中找出语义分割数据集的 NYU-v2 . 我很难理解图像标签是如何存储的。 例如,给定以下图像: 对应的标签图片为: 现在,如果我在 OpenCV 中打开标签图像,
import java.util.Random; class svg{ public static void main(String[] args){ String f="\"
我有一张 8x8 的图片。 (位图 - 可以更改) 我想做的是能够绘制一个形状,给定一个 Path 和 Paint 对象到我的 SurfaceView 上。 目前我所能做的就是用纯色填充形状。我怎样才
要在页面上显示图像,你需要使用源属性(src)。src 指 source 。源属性的值是图像的 URL 地址。 定义图像的语法是: 在浏览器无法载入图像时,替换文本属性告诉读者她们失去的信息。此
**MMEditing是基于PyTorch的图像&视频编辑开源工具箱,支持图像和视频超分辨率(super-resolution)、图像修复(inpainting)、图像抠图(matting)、
我正在尝试通过资源文件将图像插入到我的程序中,如下所示: green.png other files 当我尝试使用 QImage 或 QPixm
我是一名优秀的程序员,十分优秀!