How to remove image from QTextEdit - qtextedit

I add images to QTextEdit as shown below using pytq6.
How do I remove the inserted image, and/or their resource?
document = text_edit.document()
image = QtGui.QImageReader(path_).read() # QImage
url = QtCore.QUrl(imagename)
document.addResource(QtGui.QTextDocument.ResourceType.ImageResource.value, url, image)
cursor = text_edit.textCursor()
image_format = QtGui.QTextImageFormat()
image_format.setName(url.toString())
cursor.insertImage(image_format)

Related

Not able to add image in header as well as in body part of word file using apache poi

I'm adding a picture in the header of a word document. It shows a frame for the image and says "the image cannot currently be displayed". If I add text to the header, it shows the text, and if I add the image in the document body, it also shows the image. So it is getting the image and it shows text on the header, but not the image.
XWPFHeader head = document.createHeader(HeaderFooterType.DEFAULT);
paragraph = head.getParagraphArray(0);
if (paragraph == null)
//paragraph = head.createParagraph();
paragraph=document.createParagraph();
paragraph.setAlignment(ParagraphAlignment.RIGHT);
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("static/Picture.png");
String imgFile = "static/Picture.png";
run = paragraph.createRun();
XWPFPicture picture= run.addPicture(inputStream, XWPFDocument.PICTURE_TYPE_PNG, imgFile, Units.toEMU(100),
Units.toEMU(50));
System.out.println(picture); //XWPFPicture is added
System.out.println(picture.getPictureData()); //but without access to XWPFPictureData (no blipID)

ArcGIS Runtime : SceneView load tif file not work

I want to load a tif file into SceneView, I tried the method from this, the code is as follows:
Esri.ArcGISRuntime.Geometry.Envelope pacificSouthwestEnvelope = ...;
// Create an ImageFrame with a local image file and the extent envelope
ImageFrame imageFrame = new ImageFrame(new System.Uri(TifFilePath), pacificSouthwestEnvelope);
//ImageFrame imageFrame = new ImageFrame(image, pacificSouthwestEnvelope);
// Add the ImageFrame to an ImageOverlay and set it to be 50% transparent
ImageOverlay imageOverlay = new ImageOverlay(imageFrame);
imageOverlay.Opacity = 1;
// Add the ImageOverlay to the scene view's ImageOverlay collection
MySceneView.ImageOverlays.Add(imageOverlay);
imageFrame.LoadAsync().Wait();
await MySceneView.SetViewpointAsync(new Viewpoint(imageFrame.Extent));
But it did not succeed.
Envelope's range is obtained in arcmap.
The LoadAsync() method is called to ensure that the layer has been loaded.
Finally, I set the display range of SceneView to the range of imageFrame.
But I did not see my picture on SceneView.
Then I tried to load .png and .jpg files, but they were also unsuccessful.
I don't know what's wrong with my code?
Finally, I used RasterLayer to complete the loading of the tif file.
Raster raster = new Raster(filePath);
RasterLayer rasterLayer = new RasterLayer(raster);
MySceneView.Scene.Basemap.BaseLayers.Add(rasterLayer);

How to use Itext to add an image file into an existing PDF, and declare a unique name for it?

In order to find an added image file and replace it with another image file when I read a PDF next time, I want to use Itext to add an image file into an existing PDF, and declare a unique name for it.
My code:
final PdfName key = new PdfName("MY_SIGN_KEY");
final PdfName val = new PdfName("MY_SIGN_VAL");
Image signImage=Image.getInstance(signPngFile.getAbsolutePath());
signImage.setAlignment(1);
signImage.scaleAbsolute(newWidth, newHeight);
signImage.setAbsolutePosition(200,200);
PdfContentByte over = stamper.getOverContent(1);
PdfImage stream = new PdfImage(signImage, "", null);
stream.put(key,val);// a unique name for it.(设置唯一标识符)
//PdfIndirectObject ref=over.getPdfWriter().addToBody(stream);
//signImage.setDirectReference(ref.getIndirectReference());
over.addImage(signImage);
I have tried your code and it works for me. See the AddImageWithID example:
public void manipulatePdf(String src, String dest) throws IOException, DocumentException {
PdfReader reader = new PdfReader(src);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
Image image = Image.getInstance(IMG);
PdfImage stream = new PdfImage(image, "", null);
stream.put(new PdfName("ITXT_SpecialId"), new PdfName("123456789"));
PdfIndirectObject ref = stamper.getWriter().addToBody(stream);
image.setDirectReference(ref.getIndirectReference());
image.setAbsolutePosition(36, 400);
PdfContentByte over = stamper.getOverContent(1);
over.addImage(image);
stamper.close();
reader.close();
}
In this example, I take a file named hello.pdf and I add an image named bruno.jpg with the file hello_with_image_id.pdf as result.
The image doesn't look black:
The ID is added:
Can you try the code I shared and see if the problem persists.
I can think of one reason why you'd get a black image: in our code, we assume that a single image is added. In the case of JPEG, this is always the case. In the case of PNG or GIF though, adding one source image could result in two images being added. Strictly speaking, PDF doesn't support transparent images (depending on how you interpret the concept of transparent images). Whenever you add a single source image with transparent parts, two images will be added to the PDF: one opaque image and one image mask. The combination of the opaque image and the image mask results in something that is perceived as a transparent image. Maybe this is what happens in your case.

Wand equivalent of ImageMagick "convert -append"

I would like to write the equivalent of
convert left.jpg right.jpg +append ouput.jpg
I found something like it in another post:
files = glob('*.jpg')
with Image() as orig: # create empty Image object
for f in files:
page = Image(filename=f)
orig.sequence.append(page)
orig.save(filename='result.pdf')
and changed it to
with Image() as orig: # create empty Image object
page = Image(filename='left.jpg'); orig.sequence.append(page)
page = Image(filename='right.jpg'); orig.sequence.append(page)
orig.save(filename='output.jpg')
but the output file just shows the first file, rather than a file with the images side-by-side.
My first attempt was completely wrong, it probably makes an animated image. Provided the two images are the same size, this will do it:
with Image() as blankimage:
with Image(filename = 'imageA.tif') as imageA:
w = imageA.width; h = imageA.height
with Image(filename = 'imageB.tif') as imageB:
blankimage.blank(w*2, h)
blankimage.composite(imageA, 0, 0)
blankimage.composite(imageB, w, 0)
blankimage.save(filename = 'output.tif')

How to resize the image to be uploaded in JSP to a fix resolution?

I am uploading images for my site , I want every image uploaded to the server be of constant size.
So, when I display them from server to my site they can be uploaded quickly and the images use less server space.
code I am using to upload image using JSP.
logo_name = System.currentTimeMillis() + ".png";
File uploadedFile = new File("/www/static.appcanvas.com/"+logo_name);
item.write(uploadedFile);
Any related articles , some hints will be of great help
You didn't show us how you are parsing the upload. But, if "item is a org.apache.commons.fileupload.FileItem then you could use something lik the following.
BufferedImage bi = ImageIO.read(item.getInputStream());
Image img = bi.getScaledInstance(100,100,Image.SCALE_SMOOTH);
int w = img.getWidth();
int h = img.getHeight();
BufferedImage scaled = new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB);
Graphics2D g = scaled.createGraphics();
g.drawImage(img,0,0,null);
if(g != null) g.dispose();
ImageIO.write(scaled,"png", uploadedFile);

Resources