java multiple images with loop - image

I would like to create more then one image with a loop. Yet, it doesn't seem to work this way. The problem is that an image can't have a number as a name. Is there a way to do this?
for(int i = 0; i < getObjects().size(); i++) {
Image i = new Image(getObjects().get(i).getImagePath()));
}

Try making an ArrayList of type Image and you can store all your images there
ArrayList<Image> imageArrayList = new ArrayList<Image>();
for(int i = 0; i < getObjects().size(); i++) {
imageArrayList.add(new Image(getObjects().get(i).getImagePath());
}
If you are just starting with java don't want this to be as confusing when returning to the code maybe use something like this
ArrayList<Image> imageArrayList = new ArrayList<>();//Creates the list that will store images
for(int i = 0; i < getObjects().size(); i++) {
Image image = new Image(getObjects().get(i).getImagePath());//Create the image you want to store
imageArrayList.add(image);//Add that image to the arraylist
}

Related

why the h2 mvstore off heap store file not created

I use the following code to try MVStore off heap store:
OffHeapStore offHeap = new OffHeapStore();
MVStore s = new MVStore.Builder().fileName("c:\\temp\\h2.cache").fileStore(offHeap).open();
int count = 100;
Map<Integer, String> map1 = s.openMap("u1");
for (int i = 0; i < count; i++) {
map1.put(i, "Hello " + i);
}
s.commit();
int size1 = map1.size();
s.close();
System.out.println("=====");
MVStore s2 = new MVStore.Builder().fileStore(offHeap).open();
map1 = s2.openMap("u1");
for (int i = 0; i < size1; i++) {
System.out.println("M1>"+i+","+map1.get(i));
}
s2.close();
The code seems to work. After the code executes, the file "c:\temp\h2.cache" is not created. Why?
OffHeapStore is located in the memory of the process, but outside of Java heap. When you use custom .fileStore(something), .fileName(something) is silently ignored.
If you want to store data on the disk, you need to remove initialization of OffHeapStore, both .fileStore(offHeap) calls and add missing .fileName("c:\\temp\\h2.cache") call to the second MVStore.Builder().

Vulkan copying image from swap chain

I am using the vkCmdCopyImageToBuffer function and getting a memory access violation and don't understand why.
Here is the code:
VkBufferImageCopy region = {};
region.bufferOffset = 0;
region.bufferRowLength = width;
region.bufferImageHeight = height;
region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
region.imageSubresource.mipLevel = 0;
region.imageSubresource.baseArrayLayer = 0;
region.imageSubresource.layerCount = 1;
region.imageOffset = { 0, 0, 0 };
region.imageExtent = {
width,
height,
1
};
vkCmdCopyImageToBuffer(m_drawCmdBuffers[i], m_swapChain.buffers[i].image,
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, m_renderImage, 1, &region);
The swapchain images are created here in the initialization code:
// Get the swap chain images
images.resize(imageCount);
VK_CHECK_RESULT(fpGetSwapchainImagesKHR(device, swapChain, &imageCount, images.data()));
// Get the swap chain buffers containing the image and imageview
buffers.resize(imageCount);
for (uint32_t i = 0; i < imageCount; i++)
{
VkImageViewCreateInfo colorAttachmentView = {};
colorAttachmentView.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
colorAttachmentView.pNext = NULL;
colorAttachmentView.format = colorFormat;
colorAttachmentView.components = {
VK_COMPONENT_SWIZZLE_R,
VK_COMPONENT_SWIZZLE_G,
VK_COMPONENT_SWIZZLE_B,
VK_COMPONENT_SWIZZLE_A
};
colorAttachmentView.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
colorAttachmentView.subresourceRange.baseMipLevel = 0;
colorAttachmentView.subresourceRange.levelCount = 1;
colorAttachmentView.subresourceRange.baseArrayLayer = 0;
colorAttachmentView.subresourceRange.layerCount = 1;
colorAttachmentView.viewType = VK_IMAGE_VIEW_TYPE_2D;
colorAttachmentView.flags = 0;
buffers[i].image = images[i];
colorAttachmentView.image = buffers[i].image;
VK_CHECK_RESULT(vkCreateImageView(device, &colorAttachmentView, nullptr, &buffers[i].view));
}
And my buffer is similarly created here:
VkBufferCreateInfo createinfo = {};
createinfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
createinfo.size = width * height * 4 * sizeof(int8_t);
createinfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
createinfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
//create the image copy buffer
vkCreateBuffer(m_device, &createinfo, NULL, &m_renderImage);
I have tried different pixel formats and different createinfo.usage settings but none help.
VkSurfaceCapabilitiesKHR::supportedUsageFlags defines the limitations on the ways in which you can use the VkImages created by the swap chain. The only one that is guaranteed to be supported is color attachment; all of the other, including transfer src, are optional.
Therefore, you should not assume that you can copy from a presentable image. If you find yourself with a need to do that, you must first query that value. If it does not allow copies, then you must render to your own image, which you copy from. You can render from that image into the presentable one when you intend to present it.

"for" loop for Google Spreadsheet values not looping

I'm currently writing a statistic spreadsheet script for my guild, which reads out the class of one person and counts it on the statistic sheet.
For some reason the for loops aren't working. When I execute the script, it does nothing. Everything before the for loop seems to work. I have used the debugger, and set a debug point from the point of the for loop and the window is opening and closing after like 1 second.
This is my code as of now:
function addToStatistik() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var source_sheet = spreadsheet.getSheetByName("Raid Montag");
var source_range_names = source_sheet.getRange("C4:C13");
var source_range_setup_boss1 = source_sheet.getRange("M4:M13");
var target_sheet = spreadsheet.getSheetByName("Statistik");
var target_range_names = target_sheet.getRange("A4:A31");
var target_range_boss1 = target_sheet.getRange("K4:S31");
target_sheet.getRange(2,1).setValue("Debug1"); //testing stuff
for (var i=0; i < source_range_names.length; i++) {
for (var j=0; j < target_range_names.length; j++) {
if (source_range_names[i][0] == target_range_names[j][0]) {
if (source_range_setup_boss1[i][0].indexOf("War") > -1) {
target_sheet.getRange(9,5).setValue("TEST");
}
}
}
}
}
Someone can find any errors in there? I can't find anything and google also isnt helping me.
You are getting the range, but not the values. This line:
var source_range_names = source_sheet.getRange("C4:C13");
gets a range, but not any values.
Should be:
var source_range_names = source_sheet.getRange("C4:C13").getValues();
The outer loop never loops. There is no length of a range.
for (var i=0; i < source_range_names.length; i++) {
You don't need to change the above line, but currently the variable source_range_names is a range, and not a 2D array of values.
Before you iterate you need to get the values of the range, to achieve this you need to use the method getValues() or getDisplayValues():
function leFunction() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var source_sheet = spreadsheet.getSheetByName("Raid Montag");
var source_range_names = source_sheet.getRange("A1:C13");
var values_range_names = source_range_names.getDisplayValues();
Logger.log(values_range_names);
for (var i=0; i < values_range_names.length; i++) {
// Do Something
}
}

Deleting Particular repeated field data from Google protocol buffer

.proto file structure
message repetedMSG
{
required string data = 1;
}
message mainMSG
{
required repetedMSG_id = 1;
repeated repetedMSG rptMSG = 2;
}
I have one mainMSG and in it too many (suppose 10) repetedMSG are present.
Now i want to delete any particular repetedMSG (suppose 5th repetedMSG )from mainMSG. For this i tried 3 ways but none of them worked.
for (int j = 0; j<mainMSG->repetedMSG_size(); j++){
repetedMSG reptMsg = mainMsg->mutable_repetedMSG(j);
if (QString::fromStdString(reptMsg->data).compare("deleteMe") == 0){
*First tried way:-* reptMsg->Clear();
*Second tried Way:-* delete reptMsg;
*Third tried way:-* reptMsg->clear_formula_name();
break;
}
}
I get run-time error when i serialize the mainMSG for writing to a file i.e. when execute this line
mainMSG.SerializeToOstream (std::fstream output("C:/A/test1", std::ios::out | std::ios::trunc | std::ios::binary)) here i get run-time error
You can use RepeatedPtrField::DeleteSubrange() for this. However, be careful about using this in a loop -- people commonly write code like this which is O(n^2):
// BAD CODE! O(n^2)!
for (int i = 0; i < message.foo_size(); i++) {
if (should_filter(message.foo(i))) {
message.mutable_foo()->DeleteSubrange(i, 1);
--i;
}
}
Instead, if you plan to remove multiple elements, do something like this:
// Move all filtered elements to the end of the list.
int keep = 0; // number to keep
for (int i = 0; i < message.foo_size(); i++) {
if (should_filter(message.foo(i))) {
// Skip.
} else {
if (keep < i) {
message.mutable_foo()->SwapElements(i, keep)
}
++keep;
}
}
// Remove the filtered elements.
message.mutable_foo()->DeleteSubrange(keep, message.foo_size() - keep);

Calling name of the numbers automatically in a for loop

I have an ini file with information like:
slExpsave_0 = 0.23;
slExpsave_1 = 0.40;
slExpsave_2 = -0.85;
...
I need to use them in a loop;
...
for(var i=0; i<3; i++)
{
slExpArray[i].value = slExpsave_[i];
}
But it doesn't work.
What is the reason for this?
I'm guessing this is Javascript, so you should use an array if you want to access them within a loop:
slExpsave_ = [0.23, 0.40, -0.85];
Does this help?
Let me explain my problem more clearly.
As I did it manually, It worked as I wanted:
slExpsave_0 = 0.23;
slExpsave_1 = 0.40;
slExpsave_2 = -0.85;
slExpArray[0].value = slExpsave_0; // output is 0.23;
slExpArray[1].value = slExpsave_1; // output is 0.40;
slExpArray[2].value = slExpsave_2; // output is -0.85;
when I tried to do it automatically by put in the for loop:
the first one I tried:
for(var i=0; i<3; i++)
{
slExpArray[i].value = "slExpsave_" + i;
}
// output is slExpsave_0, slExpsave_1, slExpsave_2
the second was:
for(var i=0; i<3; i++)
{
slExpArray[i].value = slExpsave_[i];
}
// doesn't work.

Resources