How to share image loaded from server using picasso - nullpointerexception

String imageUrl = getIntent().getExtras().getString("img");
Picasso.get().load(imageUrl).into(imageView);
shareBtn.setOnClickListener(v -> {
BitmapDrawable bitmapDrawable = (BitmapDrawable) imageView.getDrawable();
Bitmap bitmap = bitmapDrawable.getBitmap();
String bitmapPath = MediaStore.Images.Media.insertImage(getContentResolver(), bitmap,"title", null);
Uri bitmapUri = Uri.parse(bitmapPath);
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_STREAM, bitmapUri);
startActivity(Intent.createChooser(shareIntent,"Share Image"));
});
This code is working well in Android 11 but in Android 9 getting null pointer exception as in image below.
enter image description here

Related

Render object inside debugger to image

In IntelliJ debugger, there's a “Show image” feature for AWT BufferedImage and Android Bitmap.
I want this feature for AWT Shape, too. I've created my own renderer which returns a BufferedImage:
Rectangle bounds = getBounds();
BufferedImage img = new BufferedImage(
(int) (bounds.getX() + bounds.getWidth()),
(int) (bounds.getY() + bounds.getHeight()),
BufferedImage.TYPE_INT_ARGB
);
Graphics2D g = (Graphics2D) img.getGraphics();
g.setColor(Color.RED);
g.fill(this);
return img;
The renderer works and returns an image but there's no option to show it; instead, I can only view its toString(): BufferedImage#bb3ca24: type = 2 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=ff000000 IntegerInterleavedRaster: width = 27 height = 24 #Bands = 4 xOff = 0 yOff = 0 dataOffset[0] 0.
How can I make IntelliJ to enable “Show image“ feature for BufferedImage returned from a custom renderer?

How to add Code128 Barcode image to existing pdf using pdfbox(1.8.12) with barcode4j library?

I am trying to generate the barcode from barcode4j library(code128bean, other barcode beans) and try to add to the existing pdf. The barcode image is getting created locally using the below code.
//Create the barcode bean
Code128Bean code128Bean = new Code128Bean();
final int dpi = 150;
code128Bean.setModuleWidth(UnitConv.in2mm(1.0f / dpi)); //makes the narrow bar
//width exactly one pixel
//bean.setCodeset(2);
code128Bean.doQuietZone(false);
//Open output file
File outputFile = new File("D:/barcode4jcod128.png"); //I dont want to create it
OutputStream code128Stream = new FileOutputStream(outputFile);
try {
//Set up the canvas provider for monochrome PNG output
BitmapCanvasProvider canvas1 = new BitmapCanvasProvider(
code128Stream, "image/x-png", dpi, BufferedImage.TYPE_BYTE_BINARY, false, 0);
//Generate the barcode
code128Bean.generateBarcode(canvas1, "123456");
//Signal end of generation
canvas1.finish();
} finally {
code128Stream.close();
}
My problem is I don't want to create an image and save it locally in filesystem and then add it as image to pdf. I just want to create dynamically i mean just create the barcode image dynamically and add it to the pdf.
How do I set the pagesize (like PDPage.PAGE_SIZE_A4) to the existing PDPages which I retrieved from catalog.getAllPages() method, like (List<PDPage> pages = catalog.getAllPages();)
Can somebody help on this?
Thank you so much for your help Tilman. Here is what i did
public static BufferedImage geBufferedImageForCode128Bean(String barcodeString) {
Code128Bean code128Bean = new Code128Bean();
final int dpi = 150;
code128Bean.setModuleWidth(UnitConv.in2mm(1.0f / dpi)); //makes the narrow bar
code128Bean.doQuietZone(false);
BitmapCanvasProvider canvas1 = new BitmapCanvasProvider(
dpi, BufferedImage.TYPE_BYTE_BINARY, false, 0
);
//Generate the barcode
code128Bean.generateBarcode(canvas1, barcodeString);
return canvas1.getBufferedImage();
}
// main code
PDDocument finalDoc = new PDDocument();
BufferedImage bufferedImage = geBufferedImageForCode128Bean("12345");
PDXObjectImage pdImage = new PDPixelMap(doc, bufferedImage);
PDPageContentStream contentStream = new PDPageContentStream(
finalDoc, pdPage, true, true, true
);
contentStream.drawXObject(pdImage, 100, 600, 50, 20);
contentStream.close();
finalDoc.addPage(pdPage);
finalDoc.save(new File("D:/Test75.pdf"));
The barcode is getting created the but it is created in vertical manner. i would like to see in horizontal manner. Thanks again for your help.
1) add an image to an existing page while keeping the content:
BitmapCanvasProvider canvas1 = new BitmapCanvasProvider(
dpi, BufferedImage.TYPE_BYTE_BINARY, false, 0
);
code128Bean.generateBarcode(canvas1, "123456");
canvas1.finish();
BufferedImage bim = canvas1.getBufferedImage();
PDXObjectImage img = new PDPixelMap(doc, bim);
PDPageContentStream contents = new PDPageContentStream(doc, page, true, true, true);
contents.drawXObject(img, 100, 600, bim.getWidth(), bim.getHeight());
contents.close();
2) set the media box to A4 on an existing page:
page.setMediaBox(PDPage.PAGE_SIZE_A4);

jcrop and imagecopyresampled crop image to all black on yii framework

Im using jcrop for the first time. Trying to go through the jcrop tutorial, im getting a black cropped image. This is the demo script from deepliquid with the appropriate yii changes. Here is my crop action that crops and displays the image
public function actionCrop()
{
$image_record = Images::model()->findByPk(Yii::app()->request->getParam('image'));
$imageUrl = '/images/uploads/'.$image_record->id.'/'.$image_record->image;
$model = new Crop;
if(isset($_POST['Crop']))
{
$model->attributes=$_POST['Crop'];
if($model->validate())
{
// form inputs are valid, do something here
$targ_w = $targ_h = 500;
$jpeg_quality = 90;
$src = $this->createAbsoluteUrl($imageUrl);
$img_r = imagecreatefromjpeg($src);
$dst_r = ImageCreateTrueColor( $targ_w, $targ_h );
imagecopyresampled($dst_r,$img_r,0,0,$model->x1,$model->y1,
$targ_w,$targ_h,$model->w,$model->h);
header('Content-type: image/jpeg');
imagejpeg($dst_r, null, $jpeg_quality);
}
}

how i decode base64 to image?

a develop a application. in this we take data from server just like name, discription, id and image, all information is show on label. But, image is not show proper.
xhr.onload = function(){ Ti.API.info('details onload');
var details = this.responseXML.documentElement;
var name_info = details.getElementsByTagName('game_name');
var disc_info = details.getElementsByTagName('game_desc');
var img_info = details.getElementsByTagName('game_image');
var g_id_info = details.getElementsByTagName('game_id');
Ti.API.info(curWin.id2);
for(var i=0;i<g_id_info.length;i++){
var gm_id = g_id_info.item(i);
var gm_nam = name_info.item(i);
var gm_dis = disc_info.item(i);
var img = img_info.item(i);
//
var image1 = Ti.Utils.base64decode(img.text);
Ti.API.info('if '+ gm_id.text );
if(curWin.id2==gm_id.text){
Ti.API.log('if ok');
name_label.text = gm_nam.text;
disc_label.text = gm_dis.text;
img_label.backgroundImage = image1;
};
};
};
if, u sure ur data whose come from serve in base64, than
You Just take a imageView and your data (image) whose come from server decode in bitmap or jpg and set in imageView.image.
I think it's working.... on ur application
You should use an ImageView, and set the image property with a Blob that contains the decoded datas.

Remove or hide PDF layer using ABCPdf?

Is is possible to remove or hide a layer from a PDF using ABCPdf or another framework?
The following C# example shows how layer 2 of page 1 can be deleted:
Doc theDoc = new Doc();
theDoc.Read("source.pdf");
int thePages = theDoc.GetInfoInt(theDoc.Root, "Pages");
int thePage = theDoc.GetInfoInt(thePages, "Page 1");
int theLayer = theDoc.GetInfoInt(thePage, "Content 2");
theDoc.Delete(theLayer);
Or perhaps you were looking for the Flatten() function?
ABCpdf contains an Example project called OCGLayers. This project shows you how to identify and redact all the items in a layer.
For example:
Properties props = Properties.FromDoc(_doc, false);
Page page = (Page)_doc.ObjectSoup[_doc.Page];
Reader reader = Reader.FromPage(props, page);
List<OptionalContent.Layer> layers = reader.GetLayers();
foreach (OptionalContent.Layer layer in layers) {
if (layer.Visible == false) {
if (reader == null)
reader = Reader.FromPage(props, page);
Reader.Redact(ref reader, layer);
}
}
UpdateLayers();
UpdatePreview();