Android ImageGridview on ActivityForResult导出为PDF
我正在使用“universal image loader 1.9.0”显示活动中用户选择的图像的网格视图,其中包含ActivityForResult Intent。Android版本在Android上测试:minSdkVersion=“16” 梅因。爪哇Android ImageGridview on ActivityForResult导出为PDF,android,gridview,itext,universal-image-loader,Android,Gridview,Itext,Universal Image Loader,我正在使用“universal image loader 1.9.0”显示活动中用户选择的图像的网格视图,其中包含ActivityForResult Intent。Android版本在Android上测试:minSdkVersion=“16” 梅因。爪哇 private void initImageLoader() { DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder() .c
private void initImageLoader() {
DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
.cacheOnDisc().imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
.bitmapConfig(Bitmap.Config.RGB_565).build();
ImageLoaderConfiguration.Builder builder = new ImageLoaderConfiguration.Builder(
this).defaultDisplayImageOptions(defaultOptions).memoryCache(
new WeakMemoryCache());
ImageLoaderConfiguration config = builder.build();
imageLoader = ImageLoader.getInstance();
imageLoader.init(config);
}
梅因。xml
<ViewSwitcher
android:id="@+id/viewSwitcher"
android:layout_width="fill_parent"
android:layout_height="315dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1" >
<GridView
android:id="@+id/gridGallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginBottom="-10dp"
android:layout_marginLeft="-10dp"
android:layout_marginRight="-10dp"
android:layout_marginTop="-10dp"
android:horizontalSpacing="-15dp"
android:numColumns="3"
android:padding="0dp"
android:verticalSpacing="-15dp"
tools:listitem="@layout/gallery_item" >
</GridView>
<ImageView
android:id="@+id/imgSinglePick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:contentDescription="@string/app_name"
android:src="@drawable/noimageavailable" />
</ViewSwitcher>
public void makeAndSharePDF(View v) {
Document documento = new Document();
try {
File f = crearFichero(NOMBRE_DOCUMENTO);
FileOutputStream ficheroPdf = new FileOutputStream(
f.getAbsolutePath());
PdfWriter writer = PdfWriter.getInstance(documento, ficheroPdf);
documento.open();
Bitmap bitmap =BitmapFactory.decodeResource(this.getResources(),R.drawable.logomail);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
Image imagen = Image.getInstance(stream.toByteArray());
imagen.scalePercent(75);
PdfPTable tabla_header = new PdfPTable(2);
tabla_header.setWidthPercentage(100);
PdfPCell logo_header = new PdfPCell();
logo_header.addElement(new Chunk(imagen, 0, 0));
logo_header.setRowspan(2);
logo_header.setBorder(0);
logo_header.setPadding(10);
tabla_header.addCell(logo_header);
PdfPCell titulo_reporte = new PdfPCell(new Paragraph("titulo reporte", font_titulo));
titulo_reporte.setHorizontalAlignment(Element.ALIGN_CENTER);
titulo_reporte.setBorder(0);
titulo_reporte.setPadding(10);
tabla_header.addCell(titulo_reporte);
Calendar date = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy",java.util.Locale.getDefault());
String formattedDate = df.format(date.getTime());
PdfPCell fecha_reporte = new PdfPCell(new Paragraph(formattedDate, font_subtitulo1));
fecha_reporte.setHorizontalAlignment(Element.ALIGN_CENTER);
fecha_reporte.setBorder(0);
fecha_reporte.setPadding(10);
tabla_header.addCell(fecha_reporte);
documento.add(tabla_header);
} catch (DocumentException e) {
Log.e(ETIQUETA_ERROR, e.getMessage());
} catch (IOException e) {
Log.e(ETIQUETA_ERROR, e.getMessage());
} finally {
documento.close();
File file = new File(Environment.getExternalStorageDirectory().getPath() + "/foldername"+"/filename.pdf");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
}
}