无法预览捕获的高质量图像

时间:2019-02-12 14:03:37

标签: android android-camera image-capture

我正在跟踪android developers guide,以捕获高质量的图像并将其保存到存储中,然后进行显示。问题是捕获图像后,尽管在存储中成功创建了图像,但我没有显示预览就被重定向到了主要活动

public void take_hq_image(View view) {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // Ensure that there's a camera activity to handle the intent
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        // Create the File where the photo should go
        File photoFile = null;
        try {
            photoFile = createImageFile();
        } catch (IOException ex) {
            // Error occurred while creating the File
        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            Uri photoURI = FileProvider.getUriForFile(this,
                    "com.example.android.fileprovider", photoFile);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
            startActivityForResult(takePictureIntent, HIGH_Q_IMAGE_CAPTURE_REQUEST);
        }
    }
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == HIGH_Q_IMAGE_CAPTURE_REQUEST && resultCode == RESULT_OK) {
        Bundle extras = data.getExtras();
        Bitmap bitmap = (Bitmap) extras.get("data");
        HQimageView.setImageBitmap(bitmap);
    }
}

1 个答案:

答案 0 :(得分:0)

将图像路径另存为字符串在currentImagePath变量中

dd LABORATORY Slot in table</h4></br>
 <B> <label>Select Day:</label></B><select id="day" name="day">
<option value="0">Monday</option>
<option value="1">Tuesday</option>
<option value="2">Wednesday</option>
<option value="3">Thursday</option>
<option value="4">Friday</option>
<option value="5">Saturday</otion>
</select>
<B> <label>Select Hour:</label></B><select name="hour" id="hour">
<option value="0">10:30 To 11:30</option>
<option value="1">11:30 To 12:30</option>
<option value="3">2:00 To 3:00</option>
<option value="4">3:00 To 4:00</option>
<option value="5">4:00 To 5:00</option>
<option value="6">5:00 To 6:00</option>
</select>
<input type="submit" id="submit" value="Submit" name="submit"></br>
<?php 
   if (isset($_POST['salarieid'])) {
      $_SESSION['div'] = $_POST['salarieid'];
      echo  $_SESSION['div'];}
     if (isset($_POST['day'])) {
      $_SESSION['day'] = $_POST['day'];
      echo  $_SESSION['day'];
  }
  if (isset($_POST['hour'])) {
      $_SESSION['hour'] = $_POST['hour'];
      echo  $_SESSION['hour'];}
?>
<p id="demo"></p>
</center>
<table id="timetable">
<tr>
 <th></th>
 <th>Monday</th>
 <th>Tuesday</th>
 <th>Wednesday</th>
 <th>Thursday</th>
 <th>Friday</th>
 <th>Saturday</th>
</tr>
<tr>
<th>10:30 to 11:30</th>
<td id="00" rowspan="2">00</td>
<td id="10" rowspan="2">10</td>
<td id="20">20</td>
<td id="30">30</td>
<td id="40">40</td>   
<td id="50">50</td>

</tr>
<tr>
<th>11:30 to 12:30</th>
<td id="01">01</td>
<td id="11">11</td>
<td id="21">21</td>
<td id="31">31</td>
<td id="41">41</td>
<td id="51">51</td>
</tr>
<tr>
<th>12:30 to 1:30</th>
<td id="02">02</td>
<td id="12">12</td>
<td id="22">22</td>
<td id="32">32</td>
<td id="42">42</td>
<td id="52">52</td>
</tr>
<tr>
<th>1:30 to 2:00</th>enter code here  
<td colspan="6"> <center>Reccess</center></td>
</tr> 
<tr>
<th>2:00 to 3:00</th>
<td id="03">03</td>
<td id="13">13</td>
<td id="23">23</td>
<td id="33">33</td>
<td id="43">43</td>
<td id="53">53</td>
</tr>
<tr>
<th>3:00 to 4:00</th>
<td id="04">04</td>
<td id="14">14</td>
<td id="24">24</td>
<td id="34">34</td>
<td id="44">44</td>
<td id="54">54</td>
</tr>
<tr>
<th>4:00 to 5:00</th>
<td id="05">05</td>
<td id="15">15</td>
<td id="25">25</td>
<td id="35">35</td>
<td id="45">45</td>
<td id="55">55</td>
</tr>
<tr>
<th id="1">5:00 to 6:00</th>
<td id="06">06</td>
<td id="16">16</td>
<td id="26">26</td>
<td id="36">36</td>
<td id="46">46</td>
<td id="56">56</td>
</tr>
</form>
<script type="text/javascript">
$("#hour,#day").on("click",function(){
var id = $("#hour").children(":selected").attr("value");
var idi = $("#day").children(":selected").attr("value");
res=idi.concat(id);
document.getElementById("demo").innerHTML = res;
$("#"+res).css("color","red")
});
</script>
</body>
</html>

然后显示预览

private File createImageFile() throws IOException {
    // Create an image file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    String imageFileName = "JPEG_" + timeStamp + "_";
    File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
    File image = File.createTempFile(
            imageFileName,  /* prefix */
            ".jpg",         /* suffix */
            storageDir      /* directory */
    );

    // Save a file: path for use with ACTION_VIEW intents
    currentImagePath = image.getAbsolutePath();
    return image;
}